From nobody Thu Apr 18 05:30:52 2024 Delivered-To: importer2@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=kernkonzept.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 162333060583359.20189880057353; Thu, 10 Jun 2021 06:10:05 -0700 (PDT) Received: from localhost ([::1]:50632 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lrKRg-0007qE-SM for importer2@patchew.org; Thu, 10 Jun 2021 09:10:04 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:34878) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lrJ9v-0003wy-C2 for qemu-devel@nongnu.org; Thu, 10 Jun 2021 07:47:39 -0400 Received: from tmave.modry.cz ([82.208.58.129]:40044) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lrJ9h-0000F7-K3 for qemu-devel@nongnu.org; Thu, 10 Jun 2021 07:47:39 -0400 Received: from 93-153-64-87.customers.tmcz.cz ([93.153.64.87] helo=octatonsil.dd1.int.kernkonzept.com) by tmave.modry.cz with esmtpa (Exim 4.92.3) (envelope-from ) id 1lrJ94-0007pw-9H; Thu, 10 Jun 2021 13:47:20 +0200 From: =?UTF-8?q?Jakub=20Jerm=C3=A1=C5=99?= To: qemu-devel@nongnu.org Subject: [PATCH] hw/nvme: be more careful when deasserting IRQs Date: Thu, 10 Jun 2021 13:46:24 +0200 Message-Id: <20210610114624.304681-1-jakub.jermar@kernkonzept.com> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Spam-Score: -3.4 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+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: softfail client-ip=82.208.58.129; envelope-from=jakub.jermar@kernkonzept.com; helo=tmave.modry.cz X-Spam_score_int: -11 X-Spam_score: -1.2 X-Spam_bar: - X-Spam_report: (-1.2 / 5.0 requ) BAYES_00=-1.9, SPF_HELO_NONE=0.001, SPF_SOFTFAIL=0.665 autolearn=no autolearn_force=no X-Spam_action: no action X-Mailman-Approved-At: Thu, 10 Jun 2021 09:08:55 -0400 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: =?UTF-8?q?Jakub=20Jerm=C3=A1=C5=99?= Errors-To: qemu-devel-bounces+importer2=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" An IRQ vector used by a completion queue cannot be deasserted without first checking if the same vector does not need to stay asserted for some other completion queue. Signed-off-by: Jakub Jermar --- hw/nvme/ctrl.c | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/hw/nvme/ctrl.c b/hw/nvme/ctrl.c index 0bcaf7192f..c0980929eb 100644 --- a/hw/nvme/ctrl.c +++ b/hw/nvme/ctrl.c @@ -473,6 +473,21 @@ static void nvme_irq_deassert(NvmeCtrl *n, NvmeCQueue = *cq) } } =20 +/* + * Check if the vector used by the cq can be deasserted, i.e. it needn't be + * asserted for some other cq. + */ +static bool nvme_irq_can_deassert(NvmeCtrl *n, NvmeCQueue *cq) +{ + for (unsigned qid =3D 0; qid < n->params.max_ioqpairs + 1; qid++) { + NvmeCQueue *q =3D n->cq[qid]; + + if (q && q->vector =3D=3D cq->vector && q->head !=3D q->tail) + return false; /* some queue needs this to stay asserted */ + } + return true; +} + static void nvme_req_clear(NvmeRequest *req) { req->ns =3D NULL; @@ -4089,7 +4104,9 @@ static uint16_t nvme_del_cq(NvmeCtrl *n, NvmeRequest = *req) trace_pci_nvme_err_invalid_del_cq_notempty(qid); return NVME_INVALID_QUEUE_DEL; } - nvme_irq_deassert(n, cq); + if (nvme_irq_can_deassert(n, cq)) { + nvme_irq_deassert(n, cq); + } trace_pci_nvme_del_cq(qid); nvme_free_cq(cq, n); return NVME_SUCCESS; @@ -5757,7 +5774,7 @@ static void nvme_process_db(NvmeCtrl *n, hwaddr addr,= int val) timer_mod(cq->timer, qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) + 5= 00); } =20 - if (cq->tail =3D=3D cq->head) { + if (nvme_irq_can_deassert(n, cq)) { nvme_irq_deassert(n, cq); } } else { --=20 2.31.1