From nobody Thu Nov 6 22:49:41 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1544615488196339.82227501210696; Wed, 12 Dec 2018 03:51:28 -0800 (PST) Received: from localhost ([::1]:44026 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gX331-0004cy-39 for importer@patchew.org; Wed, 12 Dec 2018 06:51:27 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43895) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gX31I-0003bv-N7 for qemu-devel@nongnu.org; Wed, 12 Dec 2018 06:49:43 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gX31E-00044S-O3 for qemu-devel@nongnu.org; Wed, 12 Dec 2018 06:49:40 -0500 Received: from mx1.redhat.com ([209.132.183.28]:55156) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gX31E-00040d-GZ for qemu-devel@nongnu.org; Wed, 12 Dec 2018 06:49:36 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id D3A893084297; Wed, 12 Dec 2018 11:49:34 +0000 (UTC) Received: from localhost.localdomain (ovpn-116-138.sin2.redhat.com [10.67.116.138]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 85E9D608C5; Wed, 12 Dec 2018 11:49:32 +0000 (UTC) From: P J P To: Yuval Shaia Date: Wed, 12 Dec 2018 17:17:21 +0530 Message-Id: <20181212114726.24060-2-ppandit@redhat.com> In-Reply-To: <20181212114726.24060-1-ppandit@redhat.com> References: <20181212114726.24060-1-ppandit@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.40]); Wed, 12 Dec 2018 11:49:34 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v1 1/6] rdma: check num_sge does not exceed MAX_SGE X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Prasad J Pandit , Li Qiang , Qemu Developers , Saar Amar Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" From: Prasad J Pandit rdma back-end has scatter/gather array ibv_sge[MAX_SGE=3D4] set to have 4 elements. A guest could send a 'PvrdmaSqWqe' ring element with 'num_sge' set to > MAX_SGE, which may lead to OOB access issue. Add check to avoid it. Reported-by: Saar Amar Signed-off-by: Prasad J Pandit Reviewed-by: Yuval Shaia --- hw/rdma/rdma_backend.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) Update v1: use new error code VENDOR_ERR_INV_NUM_SGE -> https://lists.gnu.org/archive/html/qemu-devel/2018-12/msg02220.html diff --git a/hw/rdma/rdma_backend.c b/hw/rdma/rdma_backend.c index ae1e4dcb29..bd4710d16f 100644 --- a/hw/rdma/rdma_backend.c +++ b/hw/rdma/rdma_backend.c @@ -476,9 +476,9 @@ void rdma_backend_post_send(RdmaBackendDev *backend_dev, } =20 pr_dbg("num_sge=3D%d\n", num_sge); - if (!num_sge) { - pr_dbg("num_sge=3D0\n"); - complete_work(IBV_WC_GENERAL_ERR, VENDOR_ERR_NO_SGE, ctx); + if (!num_sge || num_sge > MAX_SGE) { + pr_dbg("invalid num_sge=3D%d\n", num_sge); + complete_work(IBV_WC_GENERAL_ERR, VENDOR_ERR_INV_NUM_SGE, ctx); return; } =20 @@ -603,9 +603,9 @@ void rdma_backend_post_recv(RdmaBackendDev *backend_dev, } =20 pr_dbg("num_sge=3D%d\n", num_sge); - if (!num_sge) { - pr_dbg("num_sge=3D0\n"); - complete_work(IBV_WC_GENERAL_ERR, VENDOR_ERR_NO_SGE, ctx); + if (!num_sge || num_sge > MAX_SGE) { + pr_dbg("invalid num_sge=3D%d\n", num_sge); + complete_work(IBV_WC_GENERAL_ERR, VENDOR_ERR_INV_NUM_SGE, ctx); return; } =20 --=20 2.19.2 From nobody Thu Nov 6 22:49:41 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1544615484360885.743255680893; Wed, 12 Dec 2018 03:51:24 -0800 (PST) Received: from localhost ([::1]:44025 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gX32x-0004aV-CQ for importer@patchew.org; Wed, 12 Dec 2018 06:51:23 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43896) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gX31I-0003bw-N8 for qemu-devel@nongnu.org; Wed, 12 Dec 2018 06:49:43 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gX31G-00046Z-LO for qemu-devel@nongnu.org; Wed, 12 Dec 2018 06:49:40 -0500 Received: from mx1.redhat.com ([209.132.183.28]:38144) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gX31G-00045a-FI for qemu-devel@nongnu.org; Wed, 12 Dec 2018 06:49:38 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id BCA983082A26; Wed, 12 Dec 2018 11:49:37 +0000 (UTC) Received: from localhost.localdomain (ovpn-116-138.sin2.redhat.com [10.67.116.138]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 5F46D608C5; Wed, 12 Dec 2018 11:49:35 +0000 (UTC) From: P J P To: Yuval Shaia Date: Wed, 12 Dec 2018 17:17:22 +0530 Message-Id: <20181212114726.24060-3-ppandit@redhat.com> In-Reply-To: <20181212114726.24060-1-ppandit@redhat.com> References: <20181212114726.24060-1-ppandit@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.45]); Wed, 12 Dec 2018 11:49:37 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v1 2/6] pvrdma: add uar_read routine X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Prasad J Pandit , Li Qiang , Qemu Developers , Saar Amar Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" From: Prasad J Pandit Define skeleton 'uar_read' routine. Avoid NULL dereference. Reported-by: Li Qiang Signed-off-by: Prasad J Pandit --- hw/rdma/vmw/pvrdma_main.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/hw/rdma/vmw/pvrdma_main.c b/hw/rdma/vmw/pvrdma_main.c index 23dc9926e3..8a03ab4669 100644 --- a/hw/rdma/vmw/pvrdma_main.c +++ b/hw/rdma/vmw/pvrdma_main.c @@ -448,6 +448,11 @@ static const MemoryRegionOps regs_ops =3D { }, }; =20 +static uint64_t uar_read(void *opaque, hwaddr addr, unsigned size) +{ + return 0; +} + static void uar_write(void *opaque, hwaddr addr, uint64_t val, unsigned si= ze) { PVRDMADev *dev =3D opaque; @@ -489,6 +494,7 @@ static void uar_write(void *opaque, hwaddr addr, uint64= _t val, unsigned size) } =20 static const MemoryRegionOps uar_ops =3D { + .read =3D uar_read, .write =3D uar_write, .endianness =3D DEVICE_LITTLE_ENDIAN, .impl =3D { --=20 2.19.2 From nobody Thu Nov 6 22:49:41 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1544615591761362.17619964951905; Wed, 12 Dec 2018 03:53:11 -0800 (PST) Received: from localhost ([::1]:44032 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gX34g-0005qn-Ne for importer@patchew.org; Wed, 12 Dec 2018 06:53:10 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43922) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gX31K-0003c0-Ed for qemu-devel@nongnu.org; Wed, 12 Dec 2018 06:49:43 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gX31J-00048x-JZ for qemu-devel@nongnu.org; Wed, 12 Dec 2018 06:49:42 -0500 Received: from mx1.redhat.com ([209.132.183.28]:34618) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gX31J-00048O-CV for qemu-devel@nongnu.org; Wed, 12 Dec 2018 06:49:41 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id AC054C049D4B; Wed, 12 Dec 2018 11:49:40 +0000 (UTC) Received: from localhost.localdomain (ovpn-116-138.sin2.redhat.com [10.67.116.138]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 483BC608C5; Wed, 12 Dec 2018 11:49:38 +0000 (UTC) From: P J P To: Yuval Shaia Date: Wed, 12 Dec 2018 17:17:23 +0530 Message-Id: <20181212114726.24060-4-ppandit@redhat.com> In-Reply-To: <20181212114726.24060-1-ppandit@redhat.com> References: <20181212114726.24060-1-ppandit@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Wed, 12 Dec 2018 11:49:40 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v1 3/6] pvrdma: check number of pages when creating rings X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Prasad J Pandit , Li Qiang , Qemu Developers , Saar Amar Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" From: Prasad J Pandit When creating CQ/QP rings, an object can have up to PVRDMA_MAX_FAST_REG_PAGES=3D128 pages. Check 'npages' parameter to avoid excessive memory allocation or a null dereference. Reported-by: Li Qiang Signed-off-by: Prasad J Pandit Reviewed-by: Yuval Shaia --- hw/rdma/vmw/pvrdma_cmd.c | 11 +++++++++++ 1 file changed, 11 insertions(+) Update v1: move check before page dir/tbl map -> https://lists.gnu.org/archive/html/qemu-devel/2018-12/msg02257.html diff --git a/hw/rdma/vmw/pvrdma_cmd.c b/hw/rdma/vmw/pvrdma_cmd.c index 4f616d4177..e37fb18280 100644 --- a/hw/rdma/vmw/pvrdma_cmd.c +++ b/hw/rdma/vmw/pvrdma_cmd.c @@ -259,6 +259,11 @@ static int create_cq_ring(PCIDevice *pci_dev , PvrdmaR= ing **ring, int rc =3D -EINVAL; char ring_name[MAX_RING_NAME_SZ]; =20 + if (!nchunks || nchunks > PVRDMA_MAX_FAST_REG_PAGES) { + pr_dbg("invalid nchunks: %d\n", nchunks); + return rc; + } + pr_dbg("pdir_dma=3D0x%llx\n", (long long unsigned int)pdir_dma); dir =3D rdma_pci_dma_map(pci_dev, pdir_dma, TARGET_PAGE_SIZE); if (!dir) { @@ -371,6 +376,12 @@ static int create_qp_rings(PCIDevice *pci_dev, uint64_= t pdir_dma, char ring_name[MAX_RING_NAME_SZ]; uint32_t wqe_sz; =20 + if (!spages || spages > PVRDMA_MAX_FAST_REG_PAGES + || !rpages || rpages > PVRDMA_MAX_FAST_REG_PAGES) { + pr_dbg("invalid pages: %d, %d\n", spages, rpages); + return rc; + } + pr_dbg("pdir_dma=3D0x%llx\n", (long long unsigned int)pdir_dma); dir =3D rdma_pci_dma_map(pci_dev, pdir_dma, TARGET_PAGE_SIZE); if (!dir) { --=20 2.19.2 From nobody Thu Nov 6 22:49:41 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1544615607896705.9293233862664; Wed, 12 Dec 2018 03:53:27 -0800 (PST) Received: from localhost ([::1]:44033 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gX34w-0006PK-S5 for importer@patchew.org; Wed, 12 Dec 2018 06:53:26 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43945) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gX31N-0003eP-UU for qemu-devel@nongnu.org; Wed, 12 Dec 2018 06:49:46 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gX31M-0004BO-Lx for qemu-devel@nongnu.org; Wed, 12 Dec 2018 06:49:45 -0500 Received: from mx1.redhat.com ([209.132.183.28]:36906) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gX31M-0004Ad-Ca for qemu-devel@nongnu.org; Wed, 12 Dec 2018 06:49:44 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id AD140309178B; Wed, 12 Dec 2018 11:49:43 +0000 (UTC) Received: from localhost.localdomain (ovpn-116-138.sin2.redhat.com [10.67.116.138]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 3E076608C8; Wed, 12 Dec 2018 11:49:40 +0000 (UTC) From: P J P To: Yuval Shaia Date: Wed, 12 Dec 2018 17:17:24 +0530 Message-Id: <20181212114726.24060-5-ppandit@redhat.com> In-Reply-To: <20181212114726.24060-1-ppandit@redhat.com> References: <20181212114726.24060-1-ppandit@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.41]); Wed, 12 Dec 2018 11:49:43 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v1 4/6] pvrdma: release ring object in case of an error X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Prasad J Pandit , Li Qiang , Qemu Developers , Saar Amar Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" From: Prasad J Pandit create_cq and create_qp routines allocate ring object, but it's not released in case of an error, leading to memory leakage. Reported-by: Li Qiang Signed-off-by: Prasad J Pandit Reviewed-by: Yuval Shaia --- hw/rdma/vmw/pvrdma_cmd.c | 36 +++++++++++++++++++++++++----------- 1 file changed, 25 insertions(+), 11 deletions(-) Update v1: define new function to free PvrdmaRing object -> https://lists.gnu.org/archive/html/qemu-devel/2018-12/msg02328.html diff --git a/hw/rdma/vmw/pvrdma_cmd.c b/hw/rdma/vmw/pvrdma_cmd.c index e37fb18280..7e29607d2f 100644 --- a/hw/rdma/vmw/pvrdma_cmd.c +++ b/hw/rdma/vmw/pvrdma_cmd.c @@ -313,6 +313,14 @@ out: return rc; } =20 +static void destroy_cq_ring(PvrdmaRing *ring) +{ + pvrdma_ring_free(ring); + /* ring_state was in slot 1, not 0 so need to jump back */ + rdma_pci_dma_unmap(ring->dev, --ring->ring_state, TARGET_PAGE_SIZE); + g_free(ring); +} + static int create_cq(PVRDMADev *dev, union pvrdma_cmd_req *req, union pvrdma_cmd_resp *rsp) { @@ -335,6 +343,9 @@ static int create_cq(PVRDMADev *dev, union pvrdma_cmd_r= eq *req, =20 rc =3D rdma_rm_alloc_cq(&dev->rdma_dev_res, &dev->backend_dev, cmd->cq= e, &resp->cq_handle, ring); + if (rc) { + destroy_cq_ring(ring); + } =20 return rc; } @@ -355,10 +366,7 @@ static int destroy_cq(PVRDMADev *dev, union pvrdma_cmd= _req *req, } =20 ring =3D (PvrdmaRing *)cq->opaque; - pvrdma_ring_free(ring); - /* ring_state was in slot 1, not 0 so need to jump back */ - rdma_pci_dma_unmap(PCI_DEVICE(dev), --ring->ring_state, TARGET_PAGE_SI= ZE); - g_free(ring); + destroy_cq_ring(ring); =20 rdma_rm_dealloc_cq(&dev->rdma_dev_res, cmd->cq_handle); =20 @@ -456,6 +464,17 @@ out: return rc; } =20 +static void destroy_qp_rings(PvrdmaRing *ring) +{ + pr_dbg("sring=3D%p\n", &ring[0]); + pvrdma_ring_free(&ring[0]); + pr_dbg("rring=3D%p\n", &ring[1]); + pvrdma_ring_free(&ring[1]); + + rdma_pci_dma_unmap(ring->dev, ring->ring_state, TARGET_PAGE_SIZE); + g_free(ring); +} + static int create_qp(PVRDMADev *dev, union pvrdma_cmd_req *req, union pvrdma_cmd_resp *rsp) { @@ -485,6 +504,7 @@ static int create_qp(PVRDMADev *dev, union pvrdma_cmd_r= eq *req, cmd->max_recv_sge, cmd->recv_cq_handle, rings, &resp->qpn); if (rc) { + destroy_qp_rings(rings); return rc; } =20 @@ -557,13 +577,7 @@ static int destroy_qp(PVRDMADev *dev, union pvrdma_cmd= _req *req, rdma_rm_dealloc_qp(&dev->rdma_dev_res, cmd->qp_handle); =20 ring =3D (PvrdmaRing *)qp->opaque; - pr_dbg("sring=3D%p\n", &ring[0]); - pvrdma_ring_free(&ring[0]); - pr_dbg("rring=3D%p\n", &ring[1]); - pvrdma_ring_free(&ring[1]); - - rdma_pci_dma_unmap(PCI_DEVICE(dev), ring->ring_state, TARGET_PAGE_SIZE= ); - g_free(ring); + destroy_qp_rings(ring); =20 return 0; } --=20 2.19.2 From nobody Thu Nov 6 22:49:41 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1544615828984317.61164380875744; Wed, 12 Dec 2018 03:57:08 -0800 (PST) Received: from localhost ([::1]:44050 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gX38S-0000E2-I3 for importer@patchew.org; Wed, 12 Dec 2018 06:57:04 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43977) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gX31T-0003he-LG for qemu-devel@nongnu.org; Wed, 12 Dec 2018 06:49:52 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gX31P-0004DL-Jd for qemu-devel@nongnu.org; Wed, 12 Dec 2018 06:49:51 -0500 Received: from mx1.redhat.com ([209.132.183.28]:38186) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gX31P-0004Cn-Bu for qemu-devel@nongnu.org; Wed, 12 Dec 2018 06:49:47 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 9450B3001BC6; Wed, 12 Dec 2018 11:49:46 +0000 (UTC) Received: from localhost.localdomain (ovpn-116-138.sin2.redhat.com [10.67.116.138]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 4A3FC608C5; Wed, 12 Dec 2018 11:49:44 +0000 (UTC) From: P J P To: Yuval Shaia Date: Wed, 12 Dec 2018 17:17:25 +0530 Message-Id: <20181212114726.24060-6-ppandit@redhat.com> In-Reply-To: <20181212114726.24060-1-ppandit@redhat.com> References: <20181212114726.24060-1-ppandit@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.45]); Wed, 12 Dec 2018 11:49:46 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v1 5/6] pvrdma: check return value from pvrdma_idx_ring_has_ routines X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Prasad J Pandit , Li Qiang , Qemu Developers , Saar Amar Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" From: Prasad J Pandit pvrdma_idx_ring_has_[data/space] routines also return invalid index PVRDMA_INVALID_IDX[=3D-1], if ring has no data/space. Check return value from these routines to avoid plausible infinite loops. Reported-by: Li Qiang Signed-off-by: Prasad J Pandit --- hw/rdma/vmw/pvrdma_dev_ring.c | 37 +++++++++++++++++------------------ 1 file changed, 18 insertions(+), 19 deletions(-) Update v1: receive error code in idx variable, remove comments -> https://lists.gnu.org/archive/html/qemu-devel/2018-12/msg02342.html diff --git a/hw/rdma/vmw/pvrdma_dev_ring.c b/hw/rdma/vmw/pvrdma_dev_ring.c index 01247fc041..2dccac8442 100644 --- a/hw/rdma/vmw/pvrdma_dev_ring.c +++ b/hw/rdma/vmw/pvrdma_dev_ring.c @@ -73,23 +73,22 @@ out: =20 void *pvrdma_ring_next_elem_read(PvrdmaRing *ring) { - unsigned int idx =3D 0, offset; + int idx; + unsigned int offset, head; =20 - /* - pr_dbg("%s: t=3D%d, h=3D%d\n", ring->name, ring->ring_state->prod_tail, - ring->ring_state->cons_head); - */ - - if (!pvrdma_idx_ring_has_data(ring->ring_state, ring->max_elems, &idx)= ) { + idx =3D pvrdma_idx_ring_has_data(ring->ring_state, ring->max_elems, &h= ead); + if (idx <=3D 0) { pr_dbg("No more data in ring\n"); return NULL; } =20 + idx =3D pvrdma_idx(&ring->ring_state->cons_head, ring->max_elems); + if (idx < 0 || head !=3D idx) { + pr_dbg("invalid idx\n"); + return NULL; + } + offset =3D idx * ring->elem_sz; - /* - pr_dbg("idx=3D%d\n", idx); - pr_dbg("offset=3D%d\n", offset); - */ return ring->pages[offset / TARGET_PAGE_SIZE] + (offset % TARGET_PAGE_= SIZE); } =20 @@ -105,20 +104,20 @@ void pvrdma_ring_read_inc(PvrdmaRing *ring) =20 void *pvrdma_ring_next_elem_write(PvrdmaRing *ring) { - unsigned int idx, offset, tail; + int idx; + unsigned int offset, tail; =20 - /* - pr_dbg("%s: t=3D%d, h=3D%d\n", ring->name, ring->ring_state->prod_tail, - ring->ring_state->cons_head); - */ - - if (!pvrdma_idx_ring_has_space(ring->ring_state, ring->max_elems, &tai= l)) { + idx =3D pvrdma_idx_ring_has_space(ring->ring_state, ring->max_elems, &= tail); + if (idx <=3D 0) { pr_dbg("CQ is full\n"); return NULL; } =20 idx =3D pvrdma_idx(&ring->ring_state->prod_tail, ring->max_elems); - /* TODO: tail =3D=3D idx */ + if (idx < 0 || tail !=3D idx) { + pr_dbg("invalid idx\n"); + return NULL; + } =20 offset =3D idx * ring->elem_sz; return ring->pages[offset / TARGET_PAGE_SIZE] + (offset % TARGET_PAGE_= SIZE); --=20 2.19.2 From nobody Thu Nov 6 22:49:41 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 15446157562011003.7716259931195; Wed, 12 Dec 2018 03:55:56 -0800 (PST) Received: from localhost ([::1]:44047 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gX37L-00084Q-2r for importer@patchew.org; Wed, 12 Dec 2018 06:55:55 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43978) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gX31T-0003hf-LE for qemu-devel@nongnu.org; Wed, 12 Dec 2018 06:49:52 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gX31S-0004FA-Br for qemu-devel@nongnu.org; Wed, 12 Dec 2018 06:49:51 -0500 Received: from mx1.redhat.com ([209.132.183.28]:49386) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gX31S-0004Eh-5l for qemu-devel@nongnu.org; Wed, 12 Dec 2018 06:49:50 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 7DBC030024D7; Wed, 12 Dec 2018 11:49:49 +0000 (UTC) Received: from localhost.localdomain (ovpn-116-138.sin2.redhat.com [10.67.116.138]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 2F8A0608C5; Wed, 12 Dec 2018 11:49:46 +0000 (UTC) From: P J P To: Yuval Shaia Date: Wed, 12 Dec 2018 17:17:26 +0530 Message-Id: <20181212114726.24060-7-ppandit@redhat.com> In-Reply-To: <20181212114726.24060-1-ppandit@redhat.com> References: <20181212114726.24060-1-ppandit@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.43]); Wed, 12 Dec 2018 11:49:49 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v1 6/6] rdma: remove unused VENDOR_ERR_NO_SGE macro X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Prasad J Pandit , Li Qiang , Qemu Developers , Saar Amar Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" From: Prasad J Pandit Replace VENDOR_ERR_NO_SGE macro with VENDOR_ERR_INV_NUM_SGE to indicate invalid number of scatter/gather elements. Signed-off-by: Prasad J Pandit --- hw/rdma/rdma_backend.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/hw/rdma/rdma_backend.c b/hw/rdma/rdma_backend.c index bd4710d16f..c28bfbd44d 100644 --- a/hw/rdma/rdma_backend.c +++ b/hw/rdma/rdma_backend.c @@ -37,12 +37,11 @@ #define VENDOR_ERR_TOO_MANY_SGES 0x202 #define VENDOR_ERR_NOMEM 0x203 #define VENDOR_ERR_QP0 0x204 -#define VENDOR_ERR_NO_SGE 0x205 +#define VENDOR_ERR_INV_NUM_SGE 0x205 #define VENDOR_ERR_MAD_SEND 0x206 #define VENDOR_ERR_INVLKEY 0x207 #define VENDOR_ERR_MR_SMALL 0x208 #define VENDOR_ERR_INV_MAD_BUFF 0x209 -#define VENDOR_ERR_INV_NUM_SGE 0x210 =20 #define THR_NAME_LEN 16 #define THR_POLL_TO 5000 --=20 2.19.2