From nobody Mon Feb 9 08:56:56 2026 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=1603964043; cv=none; d=zohomail.com; s=zohoarc; b=P6WdDgTtJ0DUvSZIc6HcGSWLoBt6dLMIn/g53rYwKfiydZHBzfFj6nRPvFHymXZ8AgBO84W8Etx3vlFqW3tDKIyYDtT7rG1dpYjRtSVXYv9S/TIqynRXUXTqVwWsktQG/iri6trbe5ATX7tTO7RdI4dMk4pYxQTugUqnEs+kefo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1603964043; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:To; bh=JbCLCh2QwnhtqrPps05dA+PCf5WKH0hmY19HFhGchDk=; b=ByCWwJCAU03SyKxWp60YQcailvsyp4IU0F7MG1l5LOwxNkKBB9YXRJ2MJYdx+wM78Ug4X6RRYIGCCPRBtEWTuDotJV9h+pCHt75FcAFL/VHh3y/EjVWVTyX0qEynpBfKTNlwPwzAZaABmoAt3TS838vVcRmVRVrR9bBh1YSTb5Q= 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) header.from= 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 1603964043995600.7420018279863; Thu, 29 Oct 2020 02:34:03 -0700 (PDT) Received: from mail-ej1-f71.google.com (mail-ej1-f71.google.com [209.85.218.71]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-431-v0v5TktFNXaUuGpLmgjNdA-1; Thu, 29 Oct 2020 05:33:59 -0400 Received: by mail-ej1-f71.google.com with SMTP id x12so918832eju.22 for ; Thu, 29 Oct 2020 02:33:58 -0700 (PDT) Return-Path: Return-Path: Received: from x1w.redhat.com (234.red-83-42-66.dynamicip.rima-tde.net. [83.42.66.234]) by smtp.gmail.com with ESMTPSA id m20sm1180120edq.16.2020.10.29.02.33.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 29 Oct 2020 02:33:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1603964043; 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=JbCLCh2QwnhtqrPps05dA+PCf5WKH0hmY19HFhGchDk=; b=SGGxCyJPis96ojbmEHt08cD1Vm2hNHEQxJoF3vXc3twwHNBIqUjAAU0ILzYg6XtUXoA0NO 7oWbm3iX1rISr7cJtb7XUtBBJsjNcMF/fIbjHsPfqLdJi1/g6zVsah4HBxQot6ocSHPNLy AfXWMthi/U1v3h2hyH6RPf9+t3O2jWQ= X-MC-Unique: v0v5TktFNXaUuGpLmgjNdA-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=JbCLCh2QwnhtqrPps05dA+PCf5WKH0hmY19HFhGchDk=; b=SRXnUHTWpiP8OnC9GGlTPjXq55X0wyjAnklNtzca3iN3O2VRihKQ4YdZp9usgrZrMg sy3ll+IFQt4JapGStdqtN9deqSX1p9bA1q9ckyIZ6Eo3fKeM0VmKXIImmpCqpK9NHbec H0DnKJZijnbpkfn306v3qLY+HEc9nb7Gt29UFyaEVhYks69Cqql0U4Ve/dRAaWTky/vR I9iQZTqy4hR5cCdQnzdVoliNQcwm9PQUIVQLEJtCBmPaO2bkQPJVrt883hNBnR5QryQD T46y7f+vOVA+E4CUwQrmFHAkE77VHIq73Ibu363gm24L//WJ9qFy3LeOKw0riW38sZik kiKg== X-Gm-Message-State: AOAM531rwIvVHByQxfCEFgKr0gn5dzEic7YdE2tjJvoUxI23C/PUZ09F nXPFKzRN7QqvMTiM2XK1nfeSDmolUPZKRE/0DnrkKUrekQPoAE/WiJbqcbq/P0Eq8plQ9PTKN/b q9n+ga7wUuDIX8g== X-Received: by 2002:aa7:d495:: with SMTP id b21mr2864649edr.231.1603964037658; Thu, 29 Oct 2020 02:33:57 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx8RI/W8+eeUHv6rqdvFaXOPRMeMIt5JGcuoO5gG28fNCEiftgVjHEV70j9TsCew5xH5p1tkQ== X-Received: by 2002:aa7:d495:: with SMTP id b21mr2864629edr.231.1603964037415; Thu, 29 Oct 2020 02:33:57 -0700 (PDT) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: qemu-block@nongnu.org, Stefan Hajnoczi , Kevin Wolf , Klaus Jensen , Eric Auger , Max Reitz , Fam Zheng , Keith Busch , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Subject: [PATCH-for-5.2 v2 09/25] block/nvme: Use unsigned integer for queue counter/size Date: Thu, 29 Oct 2020 10:32:50 +0100 Message-Id: <20201029093306.1063879-10-philmd@redhat.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20201029093306.1063879-1-philmd@redhat.com> References: <20201029093306.1063879-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) We can not have negative queue count/size/index, use unsigned type. Rename 'nr_queues' as 'queue_count' to match the spec naming. Reviewed-by: Eric Auger Reviewed-by: Stefan Hajnoczi Tested-by: Eric Auger Signed-off-by: Philippe Mathieu-Daud=C3=A9 --- block/nvme.c | 38 ++++++++++++++++++-------------------- block/trace-events | 10 +++++----- 2 files changed, 23 insertions(+), 25 deletions(-) diff --git a/block/nvme.c b/block/nvme.c index b0629f5de80..c450499111e 100644 --- a/block/nvme.c +++ b/block/nvme.c @@ -104,7 +104,7 @@ struct BDRVNVMeState { * [1..]: io queues. */ NVMeQueuePair **queues; - int nr_queues; + unsigned queue_count; size_t page_size; /* How many uint32_t elements does each doorbell entry take. */ size_t doorbell_scale; @@ -161,7 +161,7 @@ static QemuOptsList runtime_opts =3D { }; =20 static void nvme_init_queue(BDRVNVMeState *s, NVMeQueue *q, - int nentries, int entry_bytes, Error **errp) + unsigned nentries, size_t entry_bytes, Error *= *errp) { size_t bytes; int r; @@ -206,7 +206,7 @@ static void nvme_free_req_queue_cb(void *opaque) =20 static NVMeQueuePair *nvme_create_queue_pair(BDRVNVMeState *s, AioContext *aio_context, - int idx, int size, + unsigned idx, size_t size, Error **errp) { int i, r; @@ -623,7 +623,7 @@ static bool nvme_poll_queues(BDRVNVMeState *s) bool progress =3D false; int i; =20 - for (i =3D 0; i < s->nr_queues; i++) { + for (i =3D 0; i < s->queue_count; i++) { if (nvme_poll_queue(s->queues[i])) { progress =3D true; } @@ -644,10 +644,10 @@ static void nvme_handle_event(EventNotifier *n) static bool nvme_add_io_queue(BlockDriverState *bs, Error **errp) { BDRVNVMeState *s =3D bs->opaque; - int n =3D s->nr_queues; + unsigned n =3D s->queue_count; NVMeQueuePair *q; NvmeCmd cmd; - int queue_size =3D NVME_QUEUE_SIZE; + unsigned queue_size =3D NVME_QUEUE_SIZE; =20 q =3D nvme_create_queue_pair(s, bdrv_get_aio_context(bs), n, queue_size, errp); @@ -661,7 +661,7 @@ static bool nvme_add_io_queue(BlockDriverState *bs, Err= or **errp) .cdw11 =3D cpu_to_le32(0x3), }; if (nvme_cmd_sync(bs, s->queues[INDEX_ADMIN], &cmd)) { - error_setg(errp, "Failed to create CQ io queue [%d]", n); + error_setg(errp, "Failed to create CQ io queue [%u]", n); goto out_error; } cmd =3D (NvmeCmd) { @@ -671,12 +671,12 @@ static bool nvme_add_io_queue(BlockDriverState *bs, E= rror **errp) .cdw11 =3D cpu_to_le32(0x1 | (n << 16)), }; if (nvme_cmd_sync(bs, s->queues[INDEX_ADMIN], &cmd)) { - error_setg(errp, "Failed to create SQ io queue [%d]", n); + error_setg(errp, "Failed to create SQ io queue [%u]", n); goto out_error; } s->queues =3D g_renew(NVMeQueuePair *, s->queues, n + 1); s->queues[n] =3D q; - s->nr_queues++; + s->queue_count++; return true; out_error: nvme_free_queue_pair(q); @@ -785,7 +785,7 @@ static int nvme_init(BlockDriverState *bs, const char *= device, int namespace, ret =3D -EINVAL; goto out; } - s->nr_queues =3D 1; + s->queue_count =3D 1; QEMU_BUILD_BUG_ON(NVME_QUEUE_SIZE & 0xF000); regs->aqa =3D cpu_to_le32((NVME_QUEUE_SIZE << AQA_ACQS_SHIFT) | (NVME_QUEUE_SIZE << AQA_ASQS_SHIFT)); @@ -895,10 +895,9 @@ static int nvme_enable_disable_write_cache(BlockDriver= State *bs, bool enable, =20 static void nvme_close(BlockDriverState *bs) { - int i; BDRVNVMeState *s =3D bs->opaque; =20 - for (i =3D 0; i < s->nr_queues; ++i) { + for (unsigned i =3D 0; i < s->queue_count; ++i) { nvme_free_queue_pair(s->queues[i]); } g_free(s->queues); @@ -1123,7 +1122,7 @@ static coroutine_fn int nvme_co_prw_aligned(BlockDriv= erState *bs, }; =20 trace_nvme_prw_aligned(s, is_write, offset, bytes, flags, qiov->niov); - assert(s->nr_queues > 1); + assert(s->queue_count > 1); req =3D nvme_get_free_req(ioq); assert(req); =20 @@ -1233,7 +1232,7 @@ static coroutine_fn int nvme_co_flush(BlockDriverStat= e *bs) .ret =3D -EINPROGRESS, }; =20 - assert(s->nr_queues > 1); + assert(s->queue_count > 1); req =3D nvme_get_free_req(ioq); assert(req); nvme_submit_command(ioq, req, &cmd, nvme_rw_cb, &data); @@ -1285,7 +1284,7 @@ static coroutine_fn int nvme_co_pwrite_zeroes(BlockDr= iverState *bs, cmd.cdw12 =3D cpu_to_le32(cdw12); =20 trace_nvme_write_zeroes(s, offset, bytes, flags); - assert(s->nr_queues > 1); + assert(s->queue_count > 1); req =3D nvme_get_free_req(ioq); assert(req); =20 @@ -1328,7 +1327,7 @@ static int coroutine_fn nvme_co_pdiscard(BlockDriverS= tate *bs, return -ENOTSUP; } =20 - assert(s->nr_queues > 1); + assert(s->queue_count > 1); =20 buf =3D qemu_try_memalign(s->page_size, s->page_size); if (!buf) { @@ -1408,7 +1407,7 @@ static void nvme_detach_aio_context(BlockDriverState = *bs) { BDRVNVMeState *s =3D bs->opaque; =20 - for (int i =3D 0; i < s->nr_queues; i++) { + for (unsigned i =3D 0; i < s->queue_count; i++) { NVMeQueuePair *q =3D s->queues[i]; =20 qemu_bh_delete(q->completion_bh); @@ -1429,7 +1428,7 @@ static void nvme_attach_aio_context(BlockDriverState = *bs, aio_set_event_notifier(new_context, &s->irq_notifier[MSIX_SHARED_IRQ_I= DX], false, nvme_handle_event, nvme_poll_cb); =20 - for (int i =3D 0; i < s->nr_queues; i++) { + for (unsigned i =3D 0; i < s->queue_count; i++) { NVMeQueuePair *q =3D s->queues[i]; =20 q->completion_bh =3D @@ -1446,11 +1445,10 @@ static void nvme_aio_plug(BlockDriverState *bs) =20 static void nvme_aio_unplug(BlockDriverState *bs) { - int i; BDRVNVMeState *s =3D bs->opaque; assert(s->plugged); s->plugged =3D false; - for (i =3D INDEX_IO(0); i < s->nr_queues; i++) { + for (unsigned i =3D INDEX_IO(0); i < s->queue_count; i++) { NVMeQueuePair *q =3D s->queues[i]; qemu_mutex_lock(&q->lock); nvme_kick(q); diff --git a/block/trace-events b/block/trace-events index f6a0f99df1a..8368f4acb0b 100644 --- a/block/trace-events +++ b/block/trace-events @@ -136,13 +136,13 @@ qed_aio_write_main(void *s, void *acb, int ret, uint6= 4_t offset, size_t len) "s # nvme.c nvme_controller_capability_raw(uint64_t value) "0x%08"PRIx64 nvme_controller_capability(const char *desc, uint64_t value) "%s: %"PRIu64 -nvme_kick(void *s, int queue) "s %p queue %d" +nvme_kick(void *s, unsigned q_index) "s %p q #%u" nvme_dma_flush_queue_wait(void *s) "s %p" nvme_error(int cmd_specific, int sq_head, int sqid, int cid, int status) "= cmd_specific %d sq_head %d sqid %d cid %d status 0x%x" -nvme_process_completion(void *s, int index, int inflight) "s %p queue %d i= nflight %d" -nvme_process_completion_queue_plugged(void *s, int index) "s %p queue %d" -nvme_complete_command(void *s, int index, int cid) "s %p queue %d cid %d" -nvme_submit_command(void *s, int index, int cid) "s %p queue %d cid %d" +nvme_process_completion(void *s, unsigned q_index, int inflight) "s %p q #= %u inflight %d" +nvme_process_completion_queue_plugged(void *s, unsigned q_index) "s %p q #= %u" +nvme_complete_command(void *s, unsigned q_index, int cid) "s %p q #%u cid = %d" +nvme_submit_command(void *s, unsigned q_index, int cid) "s %p q #%u cid %d" nvme_submit_command_raw(int c0, int c1, int c2, int c3, int c4, int c5, in= t c6, int c7) "%02x %02x %02x %02x %02x %02x %02x %02x" nvme_handle_event(void *s) "s %p" nvme_poll_queue(void *s, unsigned q_index) "s %p q #%u" --=20 2.26.2