From nobody Thu May 9 07:16:52 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.124; envelope-from=philmd@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=philmd@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1633538980; cv=none; d=zohomail.com; s=zohoarc; b=Jtipg4trkwaPJcKprK6DHbHVO1j4DW12KwKiSuwCNcaFPtLmtrddcuqHDgQXcie3W7p0Bjgm805r0ltGbvy9hCJV2XK9A31gxZCUrUYKSUl9UlgjkL9lkERxUT19bpKhuRRPI9Yg4Hg1Ss80wVRkYyHh3FSJIrTMByitp09tQLk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1633538980; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:To; bh=d0wXTRVmpQOHIPz9zqGtnv0qzZsKc85iVogQEdlDyD0=; b=QsqIwIPw/aVEJU0wObqpgT58/H42wXO8s028ilnH1FKDi3tZArJ86A23Knv4B1uxjkFLRNMwjnHrR0FVhA/1sb05CoElFmNVZpJQ4PPK0osPuxc82EEm7iIJFd5lX/aRwD16PbivHXAh8ujve/FneFPIagzpUHyFAypNXofdKe8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=philmd@redhat.com; dmarc=pass header.from= (p=none dis=none) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.zohomail.com with SMTPS id 1633538980865478.44129227079895; Wed, 6 Oct 2021 09:49:40 -0700 (PDT) Received: from mail-wr1-f71.google.com (mail-wr1-f71.google.com [209.85.221.71]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-441-TOzzEVtONFuub8PX-1VLNA-1; Wed, 06 Oct 2021 12:49:38 -0400 Received: by mail-wr1-f71.google.com with SMTP id l6-20020adfa386000000b00160c4c1866eso2549167wrb.4 for ; Wed, 06 Oct 2021 09:49:38 -0700 (PDT) Return-Path: Return-Path: Received: from x1w.redhat.com (118.red-83-35-24.dynamicip.rima-tde.net. [83.35.24.118]) by smtp.gmail.com with ESMTPSA id x26sm2286144wmi.30.2021.10.06.09.49.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Oct 2021 09:49:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1633538979; 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=d0wXTRVmpQOHIPz9zqGtnv0qzZsKc85iVogQEdlDyD0=; b=ZqdcR6lzKmBDBtI9sdUm96VM20XGVfgUNIXIACMkLZKQXMK1sx+XWAeEZteBC/2HOnDSlV du5vIikmlawC6Fu8ALxIJpKPi4KcII6EmTRKpjp/3wCyDlZYk7NUoPNFEHSWn9Fq24PIj0 CHK5kXipHlq/sDVAGN/wLnAlzDuQk+8= X-MC-Unique: TOzzEVtONFuub8PX-1VLNA-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=d0wXTRVmpQOHIPz9zqGtnv0qzZsKc85iVogQEdlDyD0=; b=72Id7+K36uB9GuqokOqeRk8/R+zNQQDuWXXIIM8mmgWTzWzWPmRi9DRz+3uS6b0QWD MP/m0LfsEvLfeWlUVxY2P9kLz+5FJJ8rZHaMVqY05esGHNBDtWv638tV6emovEXf+PlT /tLTl3IVE0gTC3n1/3Yx/EdM69DnHmTC1s0LkVu0oi5Hp8lq5843fGhGS4yq5L31QbrY fAYU9JBMFEknRNrqBXLdrlo+JMbpdlZBisEcBP8qlYc3nl5rLl+CYDVfv/gjrONYceLa op3sBTjv07Phd47U/lcirDOp6madUphlB+bAYlLfsx/6TjF+TY2SEFm+fIEatS1KdX/U IBHA== X-Gm-Message-State: AOAM5312+WPfZzreN5pLnMp9szrQimze37vlkuUsu+eaASdLp8g3pMTI HvGARAFQL/QE/p3AaxgoEfz9adJ+Deb4wsWHWNymS7XDbKrDbQdwrsv9XJ+XSe/KJR2CR/vf0/n o+XGwVZdTJ7Ho3Q== X-Received: by 2002:a1c:f402:: with SMTP id z2mr11082178wma.53.1633538977670; Wed, 06 Oct 2021 09:49:37 -0700 (PDT) X-Google-Smtp-Source: ABdhPJydeu1JlGJw2kKXfKAKwoIL9nQM05DbKetFZYl2QntNWdBATWFh+MyLoMXbF+gdHWtDcjzPMg== X-Received: by 2002:a1c:f402:: with SMTP id z2mr11082166wma.53.1633538977538; Wed, 06 Oct 2021 09:49:37 -0700 (PDT) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Fam Zheng , Stefan Hajnoczi , Hanna Reitz , Kevin Wolf , qemu-block@nongnu.org, Max Reitz Subject: [PATCH 1/5] block/nvme: Automatically free qemu_memalign() with QEMU_AUTO_VFREE Date: Wed, 6 Oct 2021 18:49:27 +0200 Message-Id: <20211006164931.172349-2-philmd@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20211006164931.172349-1-philmd@redhat.com> References: <20211006164931.172349-1-philmd@redhat.com> MIME-Version: 1.0 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=philmd@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1633538982148100001 Since commit 4d324c0bf65 ("introduce QEMU_AUTO_VFREE") buffers allocated by qemu_memalign() can automatically freed when using the QEMU_AUTO_VFREE macro. Use it to simplify a bit. Signed-off-by: Philippe Mathieu-Daud=C3=A9 --- block/nvme.c | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/block/nvme.c b/block/nvme.c index 1cc7b62bb4b..fefcc04abe6 100644 --- a/block/nvme.c +++ b/block/nvme.c @@ -514,10 +514,10 @@ static bool nvme_identify(BlockDriverState *bs, int n= amespace, Error **errp) { BDRVNVMeState *s =3D bs->opaque; bool ret =3D false; - union { + QEMU_AUTO_VFREE union { NvmeIdCtrl ctrl; NvmeIdNs ns; - } *id; + } *id =3D NULL; NvmeLBAF *lbaf; uint16_t oncs; int r; @@ -595,7 +595,6 @@ static bool nvme_identify(BlockDriverState *bs, int nam= espace, Error **errp) s->blkshift =3D lbaf->ds; out: qemu_vfio_dma_unmap(s->vfio, id); - qemu_vfree(id); =20 return ret; } @@ -1219,7 +1218,7 @@ static int nvme_co_prw(BlockDriverState *bs, uint64_t= offset, uint64_t bytes, { BDRVNVMeState *s =3D bs->opaque; int r; - uint8_t *buf =3D NULL; + QEMU_AUTO_VFREE uint8_t *buf =3D NULL; QEMUIOVector local_qiov; size_t len =3D QEMU_ALIGN_UP(bytes, qemu_real_host_page_size); assert(QEMU_IS_ALIGNED(offset, s->page_size)); @@ -1246,7 +1245,6 @@ static int nvme_co_prw(BlockDriverState *bs, uint64_t= offset, uint64_t bytes, if (!r && !is_write) { qemu_iovec_from_buf(qiov, 0, buf, bytes); } - qemu_vfree(buf); return r; } =20 @@ -1365,7 +1363,7 @@ static int coroutine_fn nvme_co_pdiscard(BlockDriverS= tate *bs, BDRVNVMeState *s =3D bs->opaque; NVMeQueuePair *ioq =3D s->queues[INDEX_IO(0)]; NVMeRequest *req; - NvmeDsmRange *buf; + QEMU_AUTO_VFREE NvmeDsmRange *buf =3D NULL; QEMUIOVector local_qiov; int ret; =20 @@ -1440,7 +1438,6 @@ static int coroutine_fn nvme_co_pdiscard(BlockDriverS= tate *bs, trace_nvme_dsm_done(s, offset, bytes, ret); out: qemu_iovec_destroy(&local_qiov); - qemu_vfree(buf); return ret; =20 } --=20 2.31.1 From nobody Thu May 9 07:16:52 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.124; envelope-from=philmd@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=philmd@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1633538985; cv=none; d=zohomail.com; s=zohoarc; b=Uaenw+vwd0yC1DXAKetFYeDztqkOgn3unDDIZXUBUXCEAL/l1KxbBiqbL9Vv+5mjIfzoP0CGJHxUOSNF6ld4VSZFCsAsYjDOVrePzrpLTigT1jPTdXYYB9s7LZM4+KYoeu+7h+hhuQFz8BOtAWAcwmzp8WRF6VyjXEGs0TAupg8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1633538985; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:To; bh=uyPtVC6HvIWx2rYECRqbct1GQVLi/CnHV8MyElho2m0=; b=RX61XX3JPp9kn9Ui83v+zb4VB3g2X2ErTcQeUwF+8ESyE+fPLU12d6M/x21/Ksh0tNy0E42SAllyaJbyHHTjfn4u7uW3L9nK+GBUePEjKyOqGXWop/v2p0gU918QtbYk9g9I34U33G5BYE3DUGnKy89PD1s07uNIsIz372muxvc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=philmd@redhat.com; dmarc=pass header.from= (p=none dis=none) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mx.zohomail.com with SMTPS id 1633538985734671.3044657917577; Wed, 6 Oct 2021 09:49:45 -0700 (PDT) Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.69]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-586-DDN_EYoHNIO0jzCk4d1BUQ-1; Wed, 06 Oct 2021 12:49:43 -0400 Received: by mail-wr1-f69.google.com with SMTP id h11-20020adfa4cb000000b00160c791a550so2375463wrb.6 for ; Wed, 06 Oct 2021 09:49:43 -0700 (PDT) Return-Path: Return-Path: Received: from x1w.redhat.com (118.red-83-35-24.dynamicip.rima-tde.net. [83.35.24.118]) by smtp.gmail.com with ESMTPSA id p3sm5905016wmp.43.2021.10.06.09.49.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Oct 2021 09:49:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1633538984; 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=uyPtVC6HvIWx2rYECRqbct1GQVLi/CnHV8MyElho2m0=; b=EGGtptHMWR5bhnkmRq4nc0U8ajF4PeznpwZbaxxQCXA3DQBQ9u9IhFM+KDNRpgqVWhCYnU /G2hWRS00tYzePxDIGT8ngTj93SAVdyGEBf96O7zTXc7jqh/kyqZDFXgVo+I+WJD59XsGS rHtdq92RfSOvchgJxGx+JKbX0E8x3hM= X-MC-Unique: DDN_EYoHNIO0jzCk4d1BUQ-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=uyPtVC6HvIWx2rYECRqbct1GQVLi/CnHV8MyElho2m0=; b=LJscuD6jPxFVrV7pWvcFUY+RQEjpM7Q8NBk0KFhArgfwXaKl9gLDQ+rNQ53zf7N7lu 0JI/r1yPSx47j/q2Cu5s4c/cEjMBId6rxRYocKX2C2W4bKJHaM/jB6t4outTKBfz3Oxn 8lWO8GIDki8XwTodgGFBF/bXO8W2SXvxl1Cod1D//2bhluzfQ8r75l/x0UugKBbNu8PG xFg6olsw3uZ0aJaK3g3sEb0VUDnzfPzGTPyV/kdrAaDtoKA2zF2S9WmD7qUUoWQ8Z4u6 wlH5007eRFyY0D26lSl3qvU6jDAxmbsclNj56E13r+5g9Voo9tUSG6KyGYFXE2HfgLqy pCng== X-Gm-Message-State: AOAM530p+Ry7/wdzynzKOHjrhav+Tr2iz0sYWg84zzTa01qz3u5vZvNv zN/IJWlS5ogTZ2mOgEwE6shdgqX35JdEk82ObBCgg08RT/EPJXgiXkzgSv9vRC37WHmwjXd7bda L/LKdjOjIGlRN5w== X-Received: by 2002:a7b:c314:: with SMTP id k20mr11104721wmj.50.1633538982133; Wed, 06 Oct 2021 09:49:42 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzQsYH0xOdrDeZY6YPbibs3veeOy7/Xb5lWWrxX+u9T5Y8Dqs5Uf2WytMSPIYbHg1lGNOGlxg== X-Received: by 2002:a7b:c314:: with SMTP id k20mr11104708wmj.50.1633538982005; Wed, 06 Oct 2021 09:49:42 -0700 (PDT) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Fam Zheng , Stefan Hajnoczi , Hanna Reitz , Kevin Wolf , qemu-block@nongnu.org, Max Reitz Subject: [PATCH 2/5] block/nvme: Display CQ/SQ pointer in nvme_free_queue_pair() Date: Wed, 6 Oct 2021 18:49:28 +0200 Message-Id: <20211006164931.172349-3-philmd@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20211006164931.172349-1-philmd@redhat.com> References: <20211006164931.172349-1-philmd@redhat.com> MIME-Version: 1.0 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=philmd@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1633538986104100001 For debugging purpose it is helpful to know the CQ/SQ pointers. We already have a trace event in nvme_free_queue_pair(), extend it to report these pointer addresses. Signed-off-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Stefan Hajnoczi --- block/nvme.c | 2 +- block/trace-events | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/block/nvme.c b/block/nvme.c index fefcc04abe6..0c94799a541 100644 --- a/block/nvme.c +++ b/block/nvme.c @@ -185,7 +185,7 @@ static bool nvme_init_queue(BDRVNVMeState *s, NVMeQueue= *q, =20 static void nvme_free_queue_pair(NVMeQueuePair *q) { - trace_nvme_free_queue_pair(q->index, q); + trace_nvme_free_queue_pair(q->index, q, &q->cq, &q->sq); if (q->completion_bh) { qemu_bh_delete(q->completion_bh); } diff --git a/block/trace-events b/block/trace-events index f2d0a9b62a7..491e765c611 100644 --- a/block/trace-events +++ b/block/trace-events @@ -157,7 +157,7 @@ nvme_dsm_done(void *s, int64_t offset, int64_t bytes, i= nt ret) "s %p offset 0x%" nvme_dma_map_flush(void *s) "s %p" nvme_free_req_queue_wait(void *s, unsigned q_index) "s %p q #%u" nvme_create_queue_pair(unsigned q_index, void *q, size_t size, void *aio_c= ontext, int fd) "index %u q %p size %zu aioctx %p fd %d" -nvme_free_queue_pair(unsigned q_index, void *q) "index %u q %p" +nvme_free_queue_pair(unsigned q_index, void *q, void *cq, void *sq) "index= %u q %p cq %p sq %p" nvme_cmd_map_qiov(void *s, void *cmd, void *req, void *qiov, int entries) = "s %p cmd %p req %p qiov %p entries %d" nvme_cmd_map_qiov_pages(void *s, int i, uint64_t page) "s %p page[%d] 0x%"= PRIx64 nvme_cmd_map_qiov_iov(void *s, int i, void *page, int pages) "s %p iov[%d]= %p pages %d" --=20 2.31.1 From nobody Thu May 9 07:16:52 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.124; envelope-from=philmd@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=philmd@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1633538990; cv=none; d=zohomail.com; s=zohoarc; b=fI69saATJNv/7B7VbMFyaPA50j6AgXj+jyDHpLPhprlqgtNTXHlX4Esgf0sTS1WGYt9bokcX7zo/579MjrqHouMIg30qRsB8cYXlFzMHnC9EbjN8xtkrpD1GbAB6Ds8al5pWpN4L0VHxVa5/7sd2kqLJvrMBtsWv7mlHdgm1otA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1633538990; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:To; bh=k+ZAZbWmuK9qI+HMawgY0ECoHoMJ3zL59+qK7eacaOw=; b=Xg5Vf2WveMLFpHRh54LOoZEL2o1/Bg/Npz4nqn7T8lus13oq1nCC3U3Zts3Ixgk4QL3hefJrWFwd6PXXd3KY4wQuG3iJSSgZ5Jav5kNL/fvZIsCHykxOu2w0zzpUpfV5PN97CI0nawG7/85y6HoVfSUCXMrJ1Slcf4TQG41mtWM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=philmd@redhat.com; dmarc=pass header.from= (p=none dis=none) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.zohomail.com with SMTPS id 1633538989988186.18695729608748; Wed, 6 Oct 2021 09:49:49 -0700 (PDT) Received: from mail-wr1-f70.google.com (mail-wr1-f70.google.com [209.85.221.70]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-329-SMQs6qcLMkuWc-xf2qx6-w-1; Wed, 06 Oct 2021 12:49:47 -0400 Received: by mail-wr1-f70.google.com with SMTP id l6-20020adfa386000000b00160c4c1866eso2549506wrb.4 for ; Wed, 06 Oct 2021 09:49:47 -0700 (PDT) Return-Path: Return-Path: Received: from x1w.redhat.com (118.red-83-35-24.dynamicip.rima-tde.net. [83.35.24.118]) by smtp.gmail.com with ESMTPSA id r2sm6275534wmq.28.2021.10.06.09.49.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Oct 2021 09:49:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1633538989; 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=k+ZAZbWmuK9qI+HMawgY0ECoHoMJ3zL59+qK7eacaOw=; b=Bi4ABnmGRFofKRfDdQObMTve/PGjaiEMyd0rBbWVRamgshGCM8jxTirJ31s8Tw49XGjOVN 5vx4dw/VtPi1ndU8laiwOmMGkTQS3FMhG/UaH+6RZCdD9S0oFNKsG4KsVgGKWoI5V203js hdoZks405I/SX+pUtnh5I7B01lu8JJA= X-MC-Unique: SMQs6qcLMkuWc-xf2qx6-w-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=k+ZAZbWmuK9qI+HMawgY0ECoHoMJ3zL59+qK7eacaOw=; b=AkHfawyfG51qGty6ye14qt/P3DpniwKafZ0bRdGl0Lt2N+A1UIKfC+GJbwiDXIAUXW 1UbBdrPSlINf1XRANQOcKewmL2XePUnkGloOrpKdf64p10DXK4HfFiKjXpNCRsxYGyh5 zY5rP2KnAcPgC6OGzCzsgby2igYi0mFN818KxAAXvkQYhbfkGmFq1qWmy/6TszQcQBjQ hIUuLfKLbVcsMl46JXTXGfikWGdHO6Wk9OutMLy3KQZnIWcaw7jiToSI4mpxmuWv5BPe LNclEsdjn2cFLjaYZCzEHhcystx2b9vSUzc7gjtUazudb7E31hOnBv/+lMY04hF1Jy9I 4Vrg== X-Gm-Message-State: AOAM5311zgra0jm7NK9BT7eNdiocLXJ3IOH5d394Sl/gGVaBUJXOkBhN 8vjbAw5dtyMMyo3teZRFwV6ul0q0Ety2l1ROiqcM1Y6Lt1oa1hIuc17MgxZUGC96dOW58rlmjm+ yFBI2IQWnPhm5PA== X-Received: by 2002:adf:b353:: with SMTP id k19mr30254324wrd.325.1633538986606; Wed, 06 Oct 2021 09:49:46 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzutprFgfB/UY53Z6w3HOQ7RCmMEs6QikmtESWYnrbW09dujC14zqUXYhEDaS34vi7r1rD9HA== X-Received: by 2002:adf:b353:: with SMTP id k19mr30254305wrd.325.1633538986440; Wed, 06 Oct 2021 09:49:46 -0700 (PDT) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Fam Zheng , Stefan Hajnoczi , Hanna Reitz , Kevin Wolf , qemu-block@nongnu.org, Max Reitz Subject: [PATCH 3/5] block/nvme: Extract nvme_free_queue() from nvme_free_queue_pair() Date: Wed, 6 Oct 2021 18:49:29 +0200 Message-Id: <20211006164931.172349-4-philmd@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20211006164931.172349-1-philmd@redhat.com> References: <20211006164931.172349-1-philmd@redhat.com> MIME-Version: 1.0 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=philmd@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1633538990709100001 Instead of duplicating code, extract the common helper to free a single queue. Signed-off-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Stefan Hajnoczi --- block/nvme.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/block/nvme.c b/block/nvme.c index 0c94799a541..e4f336d79c2 100644 --- a/block/nvme.c +++ b/block/nvme.c @@ -183,15 +183,20 @@ static bool nvme_init_queue(BDRVNVMeState *s, NVMeQue= ue *q, return r =3D=3D 0; } =20 +static void nvme_free_queue(NVMeQueue *q) +{ + qemu_vfree(q->queue); +} + static void nvme_free_queue_pair(NVMeQueuePair *q) { trace_nvme_free_queue_pair(q->index, q, &q->cq, &q->sq); if (q->completion_bh) { qemu_bh_delete(q->completion_bh); } + nvme_free_queue(&q->sq); + nvme_free_queue(&q->cq); qemu_vfree(q->prp_list_pages); - qemu_vfree(q->sq.queue); - qemu_vfree(q->cq.queue); qemu_mutex_destroy(&q->lock); g_free(q); } --=20 2.31.1 From nobody Thu May 9 07:16:52 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.124; envelope-from=philmd@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=philmd@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1633538995; cv=none; d=zohomail.com; s=zohoarc; b=fgrbNDSyoGJ80LCnCPJcw2QLjsdbkELoBLIXnUn2QxL79boDKtcdswThP0Kmnsp1H87Jnu6KwDVnLZOHsz3oB+d7nXVIGF6qYt6PEy2E4OPHZwTITEw/nhk6hkKaicGXXd/TxmXvNVz3+Yb8Ux5MHTgAXo5dKJXSzMDTrHkOAeM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1633538995; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:To; bh=nAMHwyEPSOT7TJ8wVCCF5DgrBGt0mBuF7+qovAFjDW4=; b=CbdJuX4Sj2ZEtSLibKMwU19woTcc3VNjZ1YC08bavPx84g4KkSwCyVqu7SPPqNCvla6gEKWTCsQnfk7KBiJRRQZ4zinKCrJiAs5V83mTSnUzSQJnu4U3e2uKvzHmBUyR0HzcrcOjBn4mqjDrd4e+mkhUDIyVOGQ65K1Ac9s2nS4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=philmd@redhat.com; dmarc=pass header.from= (p=none dis=none) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mx.zohomail.com with SMTPS id 1633538995122477.3609772240146; Wed, 6 Oct 2021 09:49:55 -0700 (PDT) Received: from mail-wr1-f70.google.com (mail-wr1-f70.google.com [209.85.221.70]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-516-Ct4vcCcbOR6VSBSLmnt9RA-1; Wed, 06 Oct 2021 12:49:52 -0400 Received: by mail-wr1-f70.google.com with SMTP id j19-20020adfb313000000b00160a9de13b3so2551054wrd.8 for ; Wed, 06 Oct 2021 09:49:51 -0700 (PDT) Return-Path: Return-Path: Received: from x1w.redhat.com (118.red-83-35-24.dynamicip.rima-tde.net. [83.35.24.118]) by smtp.gmail.com with ESMTPSA id 61sm21482602wrl.94.2021.10.06.09.49.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Oct 2021 09:49:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1633538994; 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=nAMHwyEPSOT7TJ8wVCCF5DgrBGt0mBuF7+qovAFjDW4=; b=RzOu/xhjgVXm+DgS3xjfcobaRUhQGf3qzEZcdwRteCAuTDQ3qkVm4AFJmhWyunysl/PIJo 2yTh4kvB3SpGwltxk9vPrw4gOHvTVnalcQq3Q/1z6VSdcoEGoH7vXar4JE/+OFFqXI/b3B JJdqE8P0Ivs/7xkfPb5/FfkPP3jg0Eg= X-MC-Unique: Ct4vcCcbOR6VSBSLmnt9RA-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=nAMHwyEPSOT7TJ8wVCCF5DgrBGt0mBuF7+qovAFjDW4=; b=VyruzcbdwZ7+N2uJvzFQC5tk/9NTC1Gli+4GXWpGk5jptJWiCEFNRaKKo2SIrvDlWg yfblEYZz/KT8PaStGxg0jYKbNOzcWR+rpjIxvwDty2t4m6/+mg8o6Y27Tfc0YOPep7gb Scem8C4J7aJymHX7DPe8gnVL6yRkHkBjozvBRdfhUn/A8Qcr6nC3No3fh29I9jalm6HQ vOfLnIj/kH44rvd5A7JLGCUFGnK1qR24LUFNM3us60mtrc0AQbm+eQZKP31CTkXxp2c4 grNxxFjhs75HZ3YjX3Qw+aypjjYRhETVnztQcce7AskcrRMa6/kFqEqE/zRueB4sSMGX BmCw== X-Gm-Message-State: AOAM533o8Trf+P9kI4Qee/60UckAxvQbjdbvavE6TcURTal3hv/em4Kh hLB/4uEwH6yUSnHQV8f1E0SDFTyLLOe6k5MMmABOP6uQdiLpdtRvjNGP1XeTWLxxOyvQP1frx6+ XUYn3aFwpQJsLZA== X-Received: by 2002:a05:6000:15c4:: with SMTP id y4mr29709431wry.177.1633538991026; Wed, 06 Oct 2021 09:49:51 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx088Od+UzGJjUsyPDFDGtFyPV4u0VVM3HCBTBkz5LB87TvNgTYW80kboCbqGF8FMgT3NMulw== X-Received: by 2002:a05:6000:15c4:: with SMTP id y4mr29709408wry.177.1633538990835; Wed, 06 Oct 2021 09:49:50 -0700 (PDT) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Fam Zheng , Stefan Hajnoczi , Hanna Reitz , Kevin Wolf , qemu-block@nongnu.org, Max Reitz Subject: [PATCH 4/5] block/nvme: Pass BDRVNVMeState* handle to nvme_free_queue_pair() Date: Wed, 6 Oct 2021 18:49:30 +0200 Message-Id: <20211006164931.172349-5-philmd@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20211006164931.172349-1-philmd@redhat.com> References: <20211006164931.172349-1-philmd@redhat.com> MIME-Version: 1.0 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=philmd@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1633538997338100001 In the next commit we want to access BDRVNVMeState from nvme_free_queue_pair() callee. Pass it along first. Signed-off-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Stefan Hajnoczi --- block/nvme.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/block/nvme.c b/block/nvme.c index e4f336d79c2..6e476f54b9f 100644 --- a/block/nvme.c +++ b/block/nvme.c @@ -183,19 +183,19 @@ static bool nvme_init_queue(BDRVNVMeState *s, NVMeQue= ue *q, return r =3D=3D 0; } =20 -static void nvme_free_queue(NVMeQueue *q) +static void nvme_free_queue(BDRVNVMeState *s, NVMeQueue *q) { qemu_vfree(q->queue); } =20 -static void nvme_free_queue_pair(NVMeQueuePair *q) +static void nvme_free_queue_pair(BDRVNVMeState *s, NVMeQueuePair *q) { trace_nvme_free_queue_pair(q->index, q, &q->cq, &q->sq); if (q->completion_bh) { qemu_bh_delete(q->completion_bh); } - nvme_free_queue(&q->sq); - nvme_free_queue(&q->cq); + nvme_free_queue(s, &q->sq); + nvme_free_queue(s, &q->cq); qemu_vfree(q->prp_list_pages); qemu_mutex_destroy(&q->lock); g_free(q); @@ -270,7 +270,7 @@ static NVMeQueuePair *nvme_create_queue_pair(BDRVNVMeSt= ate *s, =20 return q; fail: - nvme_free_queue_pair(q); + nvme_free_queue_pair(s, q); return NULL; } =20 @@ -693,7 +693,7 @@ static bool nvme_add_io_queue(BlockDriverState *bs, Err= or **errp) s->queue_count++; return true; out_error: - nvme_free_queue_pair(q); + nvme_free_queue_pair(s, q); return false; } =20 @@ -918,7 +918,7 @@ static void nvme_close(BlockDriverState *bs) BDRVNVMeState *s =3D bs->opaque; =20 for (unsigned i =3D 0; i < s->queue_count; ++i) { - nvme_free_queue_pair(s->queues[i]); + nvme_free_queue_pair(s, s->queues[i]); } g_free(s->queues); aio_set_event_notifier(bdrv_get_aio_context(bs), --=20 2.31.1 From nobody Thu May 9 07:16:52 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.124; envelope-from=philmd@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=philmd@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1633538999; cv=none; d=zohomail.com; s=zohoarc; b=gerPvreVAkej6QJMbFncI2z8DAvRQP9RYVC/vsNbusW8PIKlKCVLE87FKSfeaEedDzIkxXldRahMLbt8rRkWzeCLW2M7v5bgEPR1kQnZ8GVRaRwyvs/vBz+4K773spktLn06kLCO9XJF627RVlgCDVOQVO9XK3ibGKft84J8H4A= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1633538999; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:To; bh=d3SY8kt+0eUr16xiO6WRv5UUaNaOH2E74e2h2BTlxRY=; b=m2xC3ePXgfwlneU3Iv0JUowHpB/FpcckcyOW3D7/J3Y14m4C0yZlb5kYhmje5WYesW5Gzd7H0LD1NAU7KeGqxRibFF22n79SFIlxoWzlNcVDccWtX3F5NJ7PNA6fX9U7fCwed9ybQeVQWj9PCK5OImlQVH1yDX96jXeK4behcps= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=philmd@redhat.com; dmarc=pass header.from= (p=none dis=none) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mx.zohomail.com with SMTPS id 1633538999187237.53870707680232; Wed, 6 Oct 2021 09:49:59 -0700 (PDT) Received: from mail-wr1-f71.google.com (mail-wr1-f71.google.com [209.85.221.71]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-542-qUXqGNsoMLK6Dv1pTDUzpA-1; Wed, 06 Oct 2021 12:49:56 -0400 Received: by mail-wr1-f71.google.com with SMTP id l6-20020adfa386000000b00160c4c1866eso2549830wrb.4 for ; Wed, 06 Oct 2021 09:49:56 -0700 (PDT) Return-Path: Return-Path: Received: from x1w.redhat.com (118.red-83-35-24.dynamicip.rima-tde.net. [83.35.24.118]) by smtp.gmail.com with ESMTPSA id k22sm21875271wrd.59.2021.10.06.09.49.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Oct 2021 09:49:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1633538998; 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=d3SY8kt+0eUr16xiO6WRv5UUaNaOH2E74e2h2BTlxRY=; b=RBuZldxpt2+H8VjqJj4puyGxU/7Es5yOPD4FU4N4GKJc//omfMXbpSMoN9JNhbbZAy5EKf 93d3/cviQK/G5JBPUc1VGSilgnNf1zbHJo1CLKC5egJkJkK5dG8msqWdveLySDGPXCQQ7Y khG4DQzTYg3394gsYVIYzq8OMq/TdT8= X-MC-Unique: qUXqGNsoMLK6Dv1pTDUzpA-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=d3SY8kt+0eUr16xiO6WRv5UUaNaOH2E74e2h2BTlxRY=; b=RZq8LdZzB51btROeVAzhfyV4fSdPHQnpaoEFIWR1htx9k0MiKSD1IUki2gPZjooQW5 aRk0UAEgwNAhrLvdANHrS/tgvGk8EIeGMXEGVX/SU0ZS1nu1y0979hQxhSy5oVh92ilT 5w22TGmIjLRjDqpYyl+Dtlb6Dw3qX16MY90Fb5JOaORIjn2yzdAYtJ0izuukZZ/SS50z 2J1j5gepilATtNozLPWWWy8zNlznEHeIx/ruHC6DJ9B6goM69QqW3SnwdIumOTcR2Q5Q v0a30M+VI+weZcek4qBueBN/AhN///rre629d7fvuMSHxeOfolb3/Jw77Y+LhBArutWg rkPQ== X-Gm-Message-State: AOAM530bIrq/4GO+wmussUJdKG7mPu8m/Lvwscc2M7GIyfRXpCpSPAw/ DQxn5Ola/njw08deF+Gfk/58onAEFM8YCm1x/Plxjo4KLrDqPkJfBtYsSBfKCzj0fWkyZGy1cvO rC9CDZf/RV/kXkA== X-Received: by 2002:a1c:158:: with SMTP id 85mr10873929wmb.187.1633538995573; Wed, 06 Oct 2021 09:49:55 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzYXrWDPsnysXoTslg9CNi8EtDOIX+tHxKAHzrlnJ6h+EnzldDiVm9QAyPTkus4yIScFH6FPg== X-Received: by 2002:a1c:158:: with SMTP id 85mr10873911wmb.187.1633538995379; Wed, 06 Oct 2021 09:49:55 -0700 (PDT) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Fam Zheng , Stefan Hajnoczi , Hanna Reitz , Kevin Wolf , qemu-block@nongnu.org, Max Reitz Subject: [PATCH 5/5] block/nvme: Fix memory leak from nvme_init_queue() Date: Wed, 6 Oct 2021 18:49:31 +0200 Message-Id: <20211006164931.172349-6-philmd@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20211006164931.172349-1-philmd@redhat.com> References: <20211006164931.172349-1-philmd@redhat.com> MIME-Version: 1.0 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=philmd@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1633539000139100001 nvme_create_queue_pair() allocates resources with qemu_vfio_dma_map(), but we never release them. Do it in nvme_free_queue() which is called from nvme_free_queue_pair(). Reported by valgrind: =3D=3D252858=3D=3D 520,192 bytes in 1 blocks are still reachable in loss = record 8,293 of 8,302 =3D=3D252858=3D=3D at 0x4846803: memalign (vg_replace_malloc.c:1265) =3D=3D252858=3D=3D by 0x484691F: posix_memalign (vg_replace_malloc.c:1= 429) =3D=3D252858=3D=3D by 0xB8AFE4: qemu_try_memalign (oslib-posix.c:210) =3D=3D252858=3D=3D by 0xA9E315: nvme_create_queue_pair (nvme.c:229) =3D=3D252858=3D=3D by 0xAA0125: nvme_init (nvme.c:799) =3D=3D252858=3D=3D by 0xAA081C: nvme_file_open (nvme.c:953) =3D=3D252858=3D=3D by 0xA23DDD: bdrv_open_driver (block.c:1550) =3D=3D252858=3D=3D by 0xA24806: bdrv_open_common (block.c:1827) =3D=3D252858=3D=3D by 0xA2889B: bdrv_open_inherit (block.c:3747) =3D=3D252858=3D=3D by 0xA28DE4: bdrv_open (block.c:3840) =3D=3D252858=3D=3D by 0x9E0F8E: bds_tree_init (blockdev.c:675) =3D=3D252858=3D=3D by 0x9E7C74: qmp_blockdev_add (blockdev.c:3551) Fixes: bdd6a90a9e5 ("block: Add VFIO based NVMe driver") Signed-off-by: Philippe Mathieu-Daud=C3=A9 --- block/nvme.c | 1 + 1 file changed, 1 insertion(+) diff --git a/block/nvme.c b/block/nvme.c index 6e476f54b9f..903c8ffa060 100644 --- a/block/nvme.c +++ b/block/nvme.c @@ -185,6 +185,7 @@ static bool nvme_init_queue(BDRVNVMeState *s, NVMeQueue= *q, =20 static void nvme_free_queue(BDRVNVMeState *s, NVMeQueue *q) { + qemu_vfio_dma_unmap(s->vfio, q->queue); qemu_vfree(q->queue); } =20 --=20 2.31.1