From nobody Mon Feb 9 12:26:29 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1607713052; cv=none; d=zohomail.com; s=zohoarc; b=jm9YHIfAyDspa4wkJbanIxSjZMfzK3k1YpUdIIq+ZlKTVJtwZOUqIzijTCYpwWs4A8lgVPnk0i7vOEiOabNPaENCofs4xy3nmw2ZnxatQSYDXIUGAKDAlxxvv//r/bvchTGCO4Js3vzS/zwGrlUUGidgMpBGF3O63DC9aHaHKV0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1607713052; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=98MssM2QvW3aAclWNIWLlIlkksmeHEXqwEwp+/r4JC8=; b=jM3kkBNW+mJqqN37vA9nkGHa5oMkA+wBo3Z5K/ZHLc2t4MRp3xkwnw7K+/qTy2hatd97NYPmSbTJkV/sf8BlNn9dtgGANnEFhtlxaPtxjsDiSZRdqg7nOgTX29ciPDFn7G5CB+wAeZoe4zWp97ShZr+tnpmm2nZvvzjdesRe1NE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1607713052018417.38241945108246; Fri, 11 Dec 2020 10:57:32 -0800 (PST) Received: from localhost ([::1]:34766 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1knmlo-0002RU-5x for importer@patchew.org; Fri, 11 Dec 2020 13:03:56 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:51746) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1knlxp-0007VA-MS for qemu-devel@nongnu.org; Fri, 11 Dec 2020 12:12:18 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:31692) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1knlxa-0003RM-FE for qemu-devel@nongnu.org; Fri, 11 Dec 2020 12:12:17 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-72-UHUf0hriMoaHBa4eXKm5nw-1; Fri, 11 Dec 2020 12:11:57 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 0FB821005504; Fri, 11 Dec 2020 17:11:56 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-112-103.ams2.redhat.com [10.36.112.103]) by smtp.corp.redhat.com (Postfix) with ESMTPS id AC56260BE5; Fri, 11 Dec 2020 17:11:55 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id B4178112EFE5; Fri, 11 Dec 2020 18:11:52 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1607706721; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=98MssM2QvW3aAclWNIWLlIlkksmeHEXqwEwp+/r4JC8=; b=d0js0DcdmH2EfnHs8bQY8kBEDyZrQ0z1kFcKNqC7IVRbq6Q8foM1RfwR65MF1zZYsQbnun 8XX/pp14EDrzgzmCqYladKHpmF4jIv3XtMGmIMB/dPUZsukNyN7KEu/933g8bBeAAM2ecl bZ/uS1yRSiFmgehg3SsmG4GkTp4gYO8= X-MC-Unique: UHUf0hriMoaHBa4eXKm5nw-1 From: Markus Armbruster To: qemu-devel@nongnu.org Subject: [PATCH 07/20] hw/rdma: Replace QList by GQueue Date: Fri, 11 Dec 2020 18:11:39 +0100 Message-Id: <20201211171152.146877-8-armbru@redhat.com> In-Reply-To: <20201211171152.146877-1-armbru@redhat.com> References: <20201211171152.146877-1-armbru@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=armbru@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=63.128.21.124; envelope-from=armbru@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: mdroth@linux.vnet.ibm.com, Yuval Shaia Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" RdmaProtectedQList provides a thread-safe queue of int64_t on top of a QList. rdma_protected_qlist_destroy() calls qlist_destroy_obj() directly. qlist_destroy_obj() is actually for use by qobject_destroy() only. The next commit will make that obvious. The minimal fix would be calling qobject_unref() instead. But QList is actually a bad fit here. It's designed for representing JSON arrays. We're better off with a GQueue here. Replace. Cc: Yuval Shaia Cc: Marcel Apfelbaum Signed-off-by: Markus Armbruster --- hw/rdma/rdma_backend_defs.h | 2 +- hw/rdma/rdma_utils.h | 15 ++++++++------- hw/rdma/rdma_backend.c | 10 +++++----- hw/rdma/rdma_utils.c | 29 ++++++++++++++++------------- 4 files changed, 30 insertions(+), 26 deletions(-) diff --git a/hw/rdma/rdma_backend_defs.h b/hw/rdma/rdma_backend_defs.h index 0b55be3503..4e6c0ad695 100644 --- a/hw/rdma/rdma_backend_defs.h +++ b/hw/rdma/rdma_backend_defs.h @@ -43,7 +43,7 @@ typedef struct RdmaBackendDev { struct ibv_context *context; struct ibv_comp_channel *channel; uint8_t port_num; - RdmaProtectedQList recv_mads_list; + RdmaProtectedGQueue recv_mads_list; RdmaCmMux rdmacm_mux; } RdmaBackendDev; =20 diff --git a/hw/rdma/rdma_utils.h b/hw/rdma/rdma_utils.h index e7babe96cb..9fd0efd940 100644 --- a/hw/rdma/rdma_utils.h +++ b/hw/rdma/rdma_utils.h @@ -28,10 +28,10 @@ #define rdma_info_report(fmt, ...) \ info_report("%s: " fmt, "rdma", ## __VA_ARGS__) =20 -typedef struct RdmaProtectedQList { +typedef struct RdmaProtectedGQueue { QemuMutex lock; - QList *list; -} RdmaProtectedQList; + GQueue *list; +} RdmaProtectedGQueue; =20 typedef struct RdmaProtectedGSList { QemuMutex lock; @@ -40,10 +40,11 @@ typedef struct RdmaProtectedGSList { =20 void *rdma_pci_dma_map(PCIDevice *dev, dma_addr_t addr, dma_addr_t plen); void rdma_pci_dma_unmap(PCIDevice *dev, void *buffer, dma_addr_t len); -void rdma_protected_qlist_init(RdmaProtectedQList *list); -void rdma_protected_qlist_destroy(RdmaProtectedQList *list); -void rdma_protected_qlist_append_int64(RdmaProtectedQList *list, int64_t v= alue); -int64_t rdma_protected_qlist_pop_int64(RdmaProtectedQList *list); +void rdma_protected_gqueue_init(RdmaProtectedGQueue *list); +void rdma_protected_gqueue_destroy(RdmaProtectedGQueue *list); +void rdma_protected_gqueue_append_int64(RdmaProtectedGQueue *list, + int64_t value); +int64_t rdma_protected_gqueue_pop_int64(RdmaProtectedGQueue *list); void rdma_protected_gslist_init(RdmaProtectedGSList *list); void rdma_protected_gslist_destroy(RdmaProtectedGSList *list); void rdma_protected_gslist_append_int32(RdmaProtectedGSList *list, diff --git a/hw/rdma/rdma_backend.c b/hw/rdma/rdma_backend.c index 5de010b1fa..6dcdfbbbe2 100644 --- a/hw/rdma/rdma_backend.c +++ b/hw/rdma/rdma_backend.c @@ -78,7 +78,7 @@ static void clean_recv_mads(RdmaBackendDev *backend_dev) unsigned long cqe_ctx_id; =20 do { - cqe_ctx_id =3D rdma_protected_qlist_pop_int64(&backend_dev-> + cqe_ctx_id =3D rdma_protected_gqueue_pop_int64(&backend_dev-> recv_mads_list); if (cqe_ctx_id !=3D -ENOENT) { qatomic_inc(&backend_dev->rdma_dev_res->stats.missing_cqe); @@ -597,7 +597,7 @@ static unsigned int save_mad_recv_buffer(RdmaBackendDev= *backend_dev, bctx->up_ctx =3D ctx; bctx->sge =3D *sge; =20 - rdma_protected_qlist_append_int64(&backend_dev->recv_mads_list, bctx_i= d); + rdma_protected_gqueue_append_int64(&backend_dev->recv_mads_list, bctx_= id); =20 return 0; } @@ -1111,7 +1111,7 @@ static void process_incoming_mad_req(RdmaBackendDev *= backend_dev, =20 trace_mad_message("recv", msg->umad.mad, msg->umad_len); =20 - cqe_ctx_id =3D rdma_protected_qlist_pop_int64(&backend_dev->recv_mads_= list); + cqe_ctx_id =3D rdma_protected_gqueue_pop_int64(&backend_dev->recv_mads= _list); if (cqe_ctx_id =3D=3D -ENOENT) { rdma_warn_report("No more free MADs buffers, waiting for a while"); sleep(THR_POLL_TO); @@ -1185,7 +1185,7 @@ static int mad_init(RdmaBackendDev *backend_dev, Char= Backend *mad_chr_be) return -EIO; } =20 - rdma_protected_qlist_init(&backend_dev->recv_mads_list); + rdma_protected_gqueue_init(&backend_dev->recv_mads_list); =20 enable_rdmacm_mux_async(backend_dev); =20 @@ -1205,7 +1205,7 @@ static void mad_fini(RdmaBackendDev *backend_dev) { disable_rdmacm_mux_async(backend_dev); qemu_chr_fe_disconnect(backend_dev->rdmacm_mux.chr_be); - rdma_protected_qlist_destroy(&backend_dev->recv_mads_list); + rdma_protected_gqueue_destroy(&backend_dev->recv_mads_list); } =20 int rdma_backend_get_gid_index(RdmaBackendDev *backend_dev, diff --git a/hw/rdma/rdma_utils.c b/hw/rdma/rdma_utils.c index 698ed4716c..98df58f689 100644 --- a/hw/rdma/rdma_utils.c +++ b/hw/rdma/rdma_utils.c @@ -14,8 +14,6 @@ */ =20 #include "qemu/osdep.h" -#include "qapi/qmp/qlist.h" -#include "qapi/qmp/qnum.h" #include "trace.h" #include "rdma_utils.h" =20 @@ -54,41 +52,46 @@ void rdma_pci_dma_unmap(PCIDevice *dev, void *buffer, d= ma_addr_t len) } } =20 -void rdma_protected_qlist_init(RdmaProtectedQList *list) +void rdma_protected_gqueue_init(RdmaProtectedGQueue *list) { qemu_mutex_init(&list->lock); - list->list =3D qlist_new(); + list->list =3D g_queue_new(); } =20 -void rdma_protected_qlist_destroy(RdmaProtectedQList *list) +void rdma_protected_gqueue_destroy(RdmaProtectedGQueue *list) { if (list->list) { - qlist_destroy_obj(QOBJECT(list->list)); + g_queue_free_full(list->list, g_free); qemu_mutex_destroy(&list->lock); list->list =3D NULL; } } =20 -void rdma_protected_qlist_append_int64(RdmaProtectedQList *list, int64_t v= alue) +void rdma_protected_gqueue_append_int64(RdmaProtectedGQueue *list, + int64_t value) { qemu_mutex_lock(&list->lock); - qlist_append_int(list->list, value); + g_queue_push_tail(list->list, g_memdup(&value, sizeof(value))); qemu_mutex_unlock(&list->lock); } =20 -int64_t rdma_protected_qlist_pop_int64(RdmaProtectedQList *list) +int64_t rdma_protected_gqueue_pop_int64(RdmaProtectedGQueue *list) { - QObject *obj; + int64_t *valp; + int64_t val; =20 qemu_mutex_lock(&list->lock); - obj =3D qlist_pop(list->list); + + valp =3D g_queue_pop_head(list->list); qemu_mutex_unlock(&list->lock); =20 - if (!obj) { + if (!valp) { return -ENOENT; } =20 - return qnum_get_uint(qobject_to(QNum, obj)); + val =3D *valp; + g_free(valp); + return val; } =20 void rdma_protected_gslist_init(RdmaProtectedGSList *list) --=20 2.26.2