From nobody Thu Dec 18 19:40:29 2025 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=1604503728; cv=none; d=zohomail.com; s=zohoarc; b=At7Bbuj5AxdlUHQSoJqBKkfHMOSId32oNQPBdveBTjyxwbPhEfPHcFEKnlEWseZHVtxHYqPk4TzU4CU3wF0KY3cw6/Bc/QwO1QATIb/FkkgWjFEfyvtefNntwahScnrhzbassuepaLlUc1HGJiizN/0gCM76fvSQhnWRtfUlW78= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1604503728; 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=v3oouaxDpJF065O8SBfXTrl5slM9v0iK9dMfAQ8Gei8=; b=dTP5UuFfCSH17THivwyAy/OoF8VhocChOJNF6WaQUJa4yoarscNd+nyNza/3cp4A6Iezi92BhomK9PLBC2zYY+VlmuqUE2EUoA40/16P0EhPYbUd44sI9mY7KU306OKYbQPdvjkZJcIlCvum9Xw6gVYNaW6BB7VVsevm0lBgl2g= 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 1604503728949160.8969125070778; Wed, 4 Nov 2020 07:28:48 -0800 (PST) Received: from localhost ([::1]:35682 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kaKiN-0001Gy-NC for importer@patchew.org; Wed, 04 Nov 2020 10:28:47 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:59572) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kaKZv-0006cK-Vz for qemu-devel@nongnu.org; Wed, 04 Nov 2020 10:20:04 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:46287) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kaKZu-0007zF-3n for qemu-devel@nongnu.org; Wed, 04 Nov 2020 10:20:03 -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-234-RclwJOppMqaDomd45kElxA-1; Wed, 04 Nov 2020 10:19:56 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 53D1180401E; Wed, 4 Nov 2020 15:19:54 +0000 (UTC) Received: from localhost (ovpn-115-145.ams2.redhat.com [10.36.115.145]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7122E6EF4B; Wed, 4 Nov 2020 15:19:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1604503201; 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=v3oouaxDpJF065O8SBfXTrl5slM9v0iK9dMfAQ8Gei8=; b=cDnQmVDdkpgi0sIbH8JdAXNvunnAArue5dVlfCA1JUAZYOUrE5b/ans5fwWtP8oTCC4uXw 0WAJHMKe7aDithTrZmgh82w7dc6zFoaa5EPX7HQkozYwDhlOdSNxnQmNij2QbgjNW0yig/ 3DreOb0F24mL4o9cTDyoR2yfvYp5EoQ= X-MC-Unique: RclwJOppMqaDomd45kElxA-1 From: Stefan Hajnoczi To: qemu-devel@nongnu.org, Peter Maydell Subject: [PULL 11/33] block/nvme: Use unsigned integer for queue counter/size Date: Wed, 4 Nov 2020 15:18:06 +0000 Message-Id: <20201104151828.405824-12-stefanha@redhat.com> In-Reply-To: <20201104151828.405824-1-stefanha@redhat.com> References: <20201104151828.405824-1-stefanha@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 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=stefanha@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/11/03 22:09:52 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] 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_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable 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: Fam Zheng , Kevin Wolf , qemu-block@nongnu.org, =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Eduardo Habkost , kvm@vger.kernel.org, Eric Auger , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Markus Armbruster , Coiby Xu , "Dr. David Alan Gilbert" , Klaus Jensen , Stefan Hajnoczi , Keith Busch , Paolo Bonzini , Max Reitz 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" From: Philippe Mathieu-Daud=C3=A9 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 Message-id: 20201029093306.1063879-10-philmd@redhat.com Signed-off-by: Stefan Hajnoczi Tested-by: Eric Auger --- 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 b0629f5de8..c450499111 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 f6a0f99df1..8368f4acb0 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.28.0