From nobody Mon Nov 17 11:49:41 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) client-ip=63.128.21.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 63.128.21.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=1603807009; cv=none; d=zohomail.com; s=zohoarc; b=JKvoh0HFQCcpi6De6Hkyeq3Uq0DzJuAIEuA4qbSH+VArq8y8e82KpLQy9MR/Ko3QdW3+B2fdCm/0+b6IC8UQBxQIxqJLxEIwppv8Ws8BHbCX+oggqX+gfr+UywcIdnAkxpH3IVArn36OUTYxa5KQI+Y4BDtfN7IiC1aXebC84Fs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1603807009; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:To; bh=YRHflBytAvKOEPighLIKwiOsYqMDgywNA3AUBcmPj5o=; b=gePkaLOqT2DOflnk4Hbsfw24rLzJQdSPjLGQJU+71dSOxhcqhOYMNnepNvhoG5dlM1ZIporb5fJ3wSWwXL8+XB9g/3Q+nUxZt5trYNVEPt0qVDzfbWu6pAawdxgY/RHn9g7NRfjkWn239+FMR/cGEHbwPrbwPGFmrmmK7+RCtds= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.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 [63.128.21.124]) by mx.zohomail.com with SMTPS id 1603807009385877.822113039914; Tue, 27 Oct 2020 06:56:49 -0700 (PDT) Received: from mail-ed1-f72.google.com (mail-ed1-f72.google.com [209.85.208.72]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-14-kV5TeAXQO1iJiIbOsq1Nww-1; Tue, 27 Oct 2020 09:56:45 -0400 Received: by mail-ed1-f72.google.com with SMTP id w24so733858edl.3 for ; Tue, 27 Oct 2020 06:56:45 -0700 (PDT) Return-Path: Return-Path: Received: from x1w.redhat.com (237.red-88-18-140.staticip.rima-tde.net. [88.18.140.237]) by smtp.gmail.com with ESMTPSA id 11sm1082584ejy.19.2020.10.27.06.56.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Oct 2020 06:56:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1603807008; 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=YRHflBytAvKOEPighLIKwiOsYqMDgywNA3AUBcmPj5o=; b=QN+o1l/OTCXWW93ga7KbvrnlDhlj+lnMDhhXk5c6jEeh4R2K2qUdPDhCbXDuALlDrZyVBo 7hKC5MYqzwI6KIk4c92+HJFPICEErhyhtHBPJppGyYwP4qEhSb9l5Oz8uJDL0+a9IP4SV8 f9gxEh2Fh+M70H8s3/vc4I/wINsGEEM= X-MC-Unique: kV5TeAXQO1iJiIbOsq1Nww-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=YRHflBytAvKOEPighLIKwiOsYqMDgywNA3AUBcmPj5o=; b=hSHYrKJEI/X94EahPobpDa451036CrdtUY3kAUjeIBt83cIh5Zi3YR6aIF4NhzNlcd jCrz4JW14mPPJg6OhppfW1ALyw50ZB9gc5tnLRREYs5bMmn3CumpZH5mD80u+6DJmovX 83MGqRrhIHDKFiA8wDe6o/icmnBHpNhCD2Nw/e4tK90HF9USsxCZrnoEegnwMyuYxcUu 1RBU79gH+ycYBnT5+AlZhj9PzD8IGhBQve3cs4DZK2cL4RzB21GiSE+lTmjDvU0yWmQ3 gfEx80OQAgz9sDTKdd4dfYiI5SUC3SJh7BWwRpeSBsQliNaRbLlG6P5C1WK2PTZvmNLc 5MZw== X-Gm-Message-State: AOAM533SsJ/5KnGh4cXBXKQRvB29VKnZGaH1DhjqyKMQ5QgI56TAUuHC 1xpsWchbIgajNT96Md2AacgW78YTu0iEO1qVP/FhVEqvzW9dfdpPBJI+JqubDDg2mwsCCRfEvVl ydienP9PMzruEGw== X-Received: by 2002:a50:9f03:: with SMTP id b3mr2284393edf.268.1603807004100; Tue, 27 Oct 2020 06:56:44 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxLKiojXcmb2GVg4IwMH6G/vgitauYTwsK2dW7aRAEXasjzgL7BxPDzcyHc7vnnOIFVcv3ylQ== X-Received: by 2002:a50:9f03:: with SMTP id b3mr2284374edf.268.1603807003858; Tue, 27 Oct 2020 06:56:43 -0700 (PDT) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: Klaus Jensen , qemu-block@nongnu.org, Fam Zheng , Keith Busch , Eric Auger , Stefan Hajnoczi , Kevin Wolf , Max Reitz , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Subject: [PATCH 10/25] block/nvme: Use unsigned integer for queue counter/size Date: Tue, 27 Oct 2020 14:55:32 +0100 Message-Id: <20201027135547.374946-11-philmd@redhat.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20201027135547.374946-1-philmd@redhat.com> References: <20201027135547.374946-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. Signed-off-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Eric Auger Reviewed-by: Stefan Hajnoczi --- 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 30075e230ca..8b0fd59c6ea 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