From a8dd54792c2c181dcd82e6a8c648c66e3520bf73 Mon Sep 17 00:00:00 2001 From: Sasha Kotchubievsky Date: Thu, 7 Feb 2019 12:46:03 +0000 Subject: [PATCH] perf: Fix integer overflow perf application can't generate IO for NVMe namespace with more than 4G size. Example of error: "Attached to NVMe over Fabrics controller at 1.1.75.1:1023: nqn.2016-06.io.spdk.r-dcs75:rd0 WARNING: controller SPDK bdev Controller (SPDK000DEADBEAF00 ) ns 1 has invalid ns size 0 / block size 4096 for I/O size 4096 WARNING: Some requested NVMe devices were skipped No valid NVMe controllers or AIO devices found" ns_size variable is uint32_t, spdk_nvme_ns_get_size function returns uint64_t. Result can exceed the maximum size of uint32_t and ns_size remains 0. The issue introduced by commit: f2462909 Change-Id: Idc6dd8688d5d6268bda1a1d6b06a611643af6155 Signed-off-by: Sasha Kotchubievsky Reviewed-on: https://review.gerrithub.io/c/443996 (master) Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/447451 Tested-by: SPDK CI Jenkins Reviewed-by: Jim Harris Reviewed-by: Ben Walker --- examples/nvme/perf/perf.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/examples/nvme/perf/perf.c b/examples/nvme/perf/perf.c index 058b11702..57520cfe7 100644 --- a/examples/nvme/perf/perf.c +++ b/examples/nvme/perf/perf.c @@ -4,6 +4,8 @@ * Copyright (c) Intel Corporation. * All rights reserved. * + * Copyright (c) 2019 Mellanox Technologies LTD. All rights reserved. + * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: @@ -588,7 +590,8 @@ register_ns(struct spdk_nvme_ctrlr *ctrlr, struct spdk_nvme_ns *ns) { struct ns_entry *entry; const struct spdk_nvme_ctrlr_data *cdata; - uint32_t max_xfer_size, entries, ns_size, sector_size; + uint32_t max_xfer_size, entries, sector_size; + uint64_t ns_size; struct spdk_nvme_io_qpair_opts opts; cdata = spdk_nvme_ctrlr_get_data(ctrlr); @@ -606,7 +609,7 @@ register_ns(struct spdk_nvme_ctrlr *ctrlr, struct spdk_nvme_ns *ns) if (ns_size < g_io_size_bytes || sector_size > g_io_size_bytes) { printf("WARNING: controller %-20.20s (%-20.20s) ns %u has invalid " - "ns size %u / block size %u for I/O size %u\n", + "ns size %" PRIu64 " / block size %u for I/O size %u\n", cdata->mn, cdata->sn, spdk_nvme_ns_get_id(ns), ns_size, spdk_nvme_ns_get_sector_size(ns), g_io_size_bytes); g_warn = true;