mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH v2 0/3] scsi: mpi3mr: Fix error return, start_time, and timeout check in mpi3mr_bring_ioc_ready()
@ 2026-11-20 19:00 Ian Rogers
  2026-11-20 19:00 ` [PATCH v2 1/3] scsi: mpi3mr: Return error on all failure exits " Ian Rogers
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Ian Rogers @ 2026-11-20 19:00 UTC (permalink / raw)
  To: Sathya Prakash Veerichetty, Kashyap Desai, Sumit Saxena,
	Sreekanth Reddy, James E.J. Bottomley, Martin K. Petersen
  Cc: Laurence Oberman, mpi3mr-linuxdrv.pdl, linux-scsi, linux-kernel,
	llvm, Elkin Cruz, Ian Rogers

Split the mpi3mr_bring_ioc_ready() error-handling and retry fixes into
three independent patches with individual Fixes: tags as requested by
Laurence Oberman:

1. Return -1 instead of 0 on failure exits in mpi3mr_bring_ioc_ready()
   when retval is 0 (such as unrecoverable controller faults, hot-unplug
   during reset/diag-save waits, or ready-state faults and timeouts
   after mpi3mr_setup_admin_qpair() sets retval = 0).
2. Initialize start_time = jiffies on entry and guard the post-enable
   timestamp reset with a boolean flag so pre-enable failures and
   subsequent retries never read an uninitialized start_time.
3. Rewrite 'elapsed_time_sec < (mrioc->ready_timeout - 60)' as
   'elapsed_time_sec + 60 < mrioc->ready_timeout' to avoid 32-bit
   unsigned underflow if a controller reports ready_timeout < 60.

v2:
  - Split v1 into three patches, each with its own Fixes: tag (Laurence
    Oberman).
  - Move 'if (!retval) retval = -1;' to 'out_device_not_present:' in
    patch 1 so a single hunk covers both out_failed fallthroughs and
    early out_device_not_present jumps cleanly for stable backports.
  - Add Laurence's Reviewed-by tag on patches 1 and 2, and note the
    510s (570s - 60s) firmware timeout math from commit 9634bb07083c in
    patch 3.

v1: https://lore.kernel.org/r/20261119170900.1530138-1-irogers@google.com

Ian Rogers (3):
  scsi: mpi3mr: Return error on all failure exits in
    mpi3mr_bring_ioc_ready()
  scsi: mpi3mr: Initialize start_time on all paths in
    mpi3mr_bring_ioc_ready()
  scsi: mpi3mr: Avoid ready_timeout underflow in
    mpi3mr_bring_ioc_ready()

 drivers/scsi/mpi3mr/mpi3mr_fw.c | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

-- 
2.56.1.750.gf70dc682cf-goog


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH v2 1/3] scsi: mpi3mr: Return error on all failure exits in mpi3mr_bring_ioc_ready()
  2026-11-20 19:00 [PATCH v2 0/3] scsi: mpi3mr: Fix error return, start_time, and timeout check in mpi3mr_bring_ioc_ready() Ian Rogers
@ 2026-11-20 19:00 ` Ian Rogers
  2026-11-20 19:00 ` [PATCH v2 2/3] scsi: mpi3mr: Initialize start_time on all paths " Ian Rogers
  2026-11-20 19:00 ` [PATCH v2 3/3] scsi: mpi3mr: Avoid ready_timeout underflow " Ian Rogers
  2 siblings, 0 replies; 4+ messages in thread
From: Ian Rogers @ 2026-11-20 19:00 UTC (permalink / raw)
  To: Sathya Prakash Veerichetty, Kashyap Desai, Sumit Saxena,
	Sreekanth Reddy, James E.J. Bottomley, Martin K. Petersen
  Cc: Laurence Oberman, mpi3mr-linuxdrv.pdl, linux-scsi, linux-kernel,
	llvm, Elkin Cruz, Ian Rogers, stable

In mpi3mr_bring_ioc_ready(), all success paths return 0 directly, while
all failure paths either fall through out_failed or jump to
out_device_not_present and return retval.

However, retval is initialized to 0 at function entry and overwritten
with 0 once mpi3mr_setup_admin_qpair() succeeds. As a result, failure
paths that do not set retval themselves - including unrecoverable fault
checks, PCI device removal during reset or diagnostic-save waits,
failure to reach MRIOC_STATE_RESET, and ready-loop fault/reset-history
exits or timeouts - return 0 (success) to mpi3mr_init_ioc() and
mpi3mr_reinit_ioc(), causing initialization to proceed against a failed
or absent controller.

Set retval = -1 at out_device_not_present whenever retval is 0 so every
failure exit returns a non-zero error while preserving specific error
codes from helper calls.

Found during an x86_64 LLVM=1 allyesconfig warning audit with AI coding
assistant help. Verified with a standalone C logic reproducer and by
building drivers/scsi/mpi3mr/mpi3mr_fw.o with LLVM=1 W=1 (-Werror); not
runtime-tested on MPI3 hardware.

Fixes: 59bd9cfe3fa0 ("scsi: mpi3mr: Code refactor of IOC init - part2")
Cc: stable@vger.kernel.org
Reviewed-by: Laurence Oberman <loberman@redhat.com>
Signed-off-by: Ian Rogers <irogers@google.com>
---
 drivers/scsi/mpi3mr/mpi3mr_fw.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/scsi/mpi3mr/mpi3mr_fw.c b/drivers/scsi/mpi3mr/mpi3mr_fw.c
index f0d3cd398dd0..416f27c37535 100644
--- a/drivers/scsi/mpi3mr/mpi3mr_fw.c
+++ b/drivers/scsi/mpi3mr/mpi3mr_fw.c
@@ -1744,6 +1744,8 @@ out_failed:
 	    "failed to bring to ready state,  current state: %s\n",
 	    mpi3mr_iocstate_name(ioc_state));
 out_device_not_present:
+	if (!retval)
+		retval = -1;
 	return retval;
 }
 
-- 
2.56.1.750.gf70dc682cf-goog


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH v2 2/3] scsi: mpi3mr: Initialize start_time on all paths in mpi3mr_bring_ioc_ready()
  2026-11-20 19:00 [PATCH v2 0/3] scsi: mpi3mr: Fix error return, start_time, and timeout check in mpi3mr_bring_ioc_ready() Ian Rogers
  2026-11-20 19:00 ` [PATCH v2 1/3] scsi: mpi3mr: Return error on all failure exits " Ian Rogers
@ 2026-11-20 19:00 ` Ian Rogers
  2026-11-20 19:00 ` [PATCH v2 3/3] scsi: mpi3mr: Avoid ready_timeout underflow " Ian Rogers
  2 siblings, 0 replies; 4+ messages in thread
From: Ian Rogers @ 2026-11-20 19:00 UTC (permalink / raw)
  To: Sathya Prakash Veerichetty, Kashyap Desai, Sumit Saxena,
	Sreekanth Reddy, James E.J. Bottomley, Martin K. Petersen
  Cc: Laurence Oberman, mpi3mr-linuxdrv.pdl, linux-scsi, linux-kernel,
	llvm, Elkin Cruz, Ian Rogers, stable

In mpi3mr_bring_ioc_ready(), start_time is only assigned after writing
MPI3_SYSIF_IOC_CONFIG_ENABLE_IOC when retry == 0, which sits after three
earlier 'goto out_failed' error paths (soft reset failure, failure to
reach MRIOC_STATE_RESET, and admin queue setup failure).

If any of those pre-enable steps fails on the first attempt, out_failed
computes elapsed_time_sec from an uninitialized start_time. Furthermore,
if out_failed decides to retry (retry == 1) and the second attempt
reaches the ready-polling loop, 'if (retry == 0)' skips assigning
start_time, leaving the ready-polling loop comparing against
uninitialized stack memory as well.

Initialize start_time = jiffies at function entry to cover pre-enable
failure exits, and replace 'if (retry == 0)' with a boolean
enable_started check so start_time is reset the first time IOC enable is
written without pre-enable waits draining ready_timeout.

Found via Clang -Wconditional-uninitialized on an x86_64 allyesconfig
build with AI coding assistant help. Verified with a standalone C
reproducer under ASan/UBSan and by building
drivers/scsi/mpi3mr/mpi3mr_fw.o with LLVM=1 W=1 (-Werror) and
-Wconditional-uninitialized; not runtime-tested on MPI3 hardware.

Fixes: 9634bb07083c ("scsi: mpi3mr: Enhance the Enable Controller retry logic")
Cc: stable@vger.kernel.org
Reviewed-by: Laurence Oberman <loberman@redhat.com>
Signed-off-by: Ian Rogers <irogers@google.com>
---
 drivers/scsi/mpi3mr/mpi3mr_fw.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/drivers/scsi/mpi3mr/mpi3mr_fw.c b/drivers/scsi/mpi3mr/mpi3mr_fw.c
index 416f27c37535..1aeae8a55b1b 100644
--- a/drivers/scsi/mpi3mr/mpi3mr_fw.c
+++ b/drivers/scsi/mpi3mr/mpi3mr_fw.c
@@ -1582,8 +1582,9 @@ static int mpi3mr_bring_ioc_ready(struct mpi3mr_ioc *mrioc)
 	int retval = 0;
 	enum mpi3mr_iocstate ioc_state;
 	u64 base_info;
+	bool enable_started = false;
 	u8 retry = 0;
-	u64 start_time, elapsed_time_sec;
+	u64 start_time = jiffies, elapsed_time_sec;
 
 retry_bring_ioc_ready:
 
@@ -1690,8 +1691,10 @@ retry_bring_ioc_ready:
 	ioc_config |= MPI3_SYSIF_IOC_CONFIG_ENABLE_IOC;
 	writel(ioc_config, &mrioc->sysif_regs->ioc_configuration);
 
-	if (retry == 0)
+	if (!enable_started) {
 		start_time = jiffies;
+		enable_started = true;
+	}
 
 	timeout = mrioc->ready_timeout * 10;
 	do {
-- 
2.56.1.750.gf70dc682cf-goog


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH v2 3/3] scsi: mpi3mr: Avoid ready_timeout underflow in mpi3mr_bring_ioc_ready()
  2026-11-20 19:00 [PATCH v2 0/3] scsi: mpi3mr: Fix error return, start_time, and timeout check in mpi3mr_bring_ioc_ready() Ian Rogers
  2026-11-20 19:00 ` [PATCH v2 1/3] scsi: mpi3mr: Return error on all failure exits " Ian Rogers
  2026-11-20 19:00 ` [PATCH v2 2/3] scsi: mpi3mr: Initialize start_time on all paths " Ian Rogers
@ 2026-11-20 19:00 ` Ian Rogers
  2 siblings, 0 replies; 4+ messages in thread
From: Ian Rogers @ 2026-11-20 19:00 UTC (permalink / raw)
  To: Sathya Prakash Veerichetty, Kashyap Desai, Sumit Saxena,
	Sreekanth Reddy, James E.J. Bottomley, Martin K. Petersen
  Cc: Laurence Oberman, mpi3mr-linuxdrv.pdl, linux-scsi, linux-kernel,
	llvm, Elkin Cruz, Ian Rogers, stable

Commit 9634bb07083c ("scsi: mpi3mr: Enhance the Enable Controller retry
logic") caps cumulative enable retries at 'mrioc->ready_timeout - 60'
(510 seconds on firmware advertising a 570-second ready timeout) so a
retry is not started with less than 60 seconds remaining.

Because mrioc->ready_timeout is a u32 read from the controller's
ioc_information register, any value below 60 (for example 0 from a
broken or disconnected controller) wraps around in 32-bit unsigned
arithmetic (e.g. 0xffffffc4) before zero-extending to u64 for the
comparison with elapsed_time_sec, spuriously retrying instead of
aborting.

Rewrite the check as 'elapsed_time_sec + 60 < mrioc->ready_timeout' to
avoid unsigned underflow while preserving the 60-second margin when
ready_timeout >= 60. (Note that if any firmware legitimately advertises
ready_timeout < 60, no retries will be attempted.)

Found during code inspection alongside a Clang warning audit with AI
coding assistant help. Verified with a standalone C reproducer under
UBSan and by building drivers/scsi/mpi3mr/mpi3mr_fw.o with LLVM=1 W=1
(-Werror); not runtime-tested on MPI3 hardware.

Fixes: 9634bb07083c ("scsi: mpi3mr: Enhance the Enable Controller retry logic")
Cc: stable@vger.kernel.org
Signed-off-by: Ian Rogers <irogers@google.com>
---
 drivers/scsi/mpi3mr/mpi3mr_fw.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/scsi/mpi3mr/mpi3mr_fw.c b/drivers/scsi/mpi3mr/mpi3mr_fw.c
index 1aeae8a55b1b..45544ad21a6e 100644
--- a/drivers/scsi/mpi3mr/mpi3mr_fw.c
+++ b/drivers/scsi/mpi3mr/mpi3mr_fw.c
@@ -1734,7 +1734,7 @@ retry_bring_ioc_ready:
 
 out_failed:
 	elapsed_time_sec = jiffies_to_msecs(jiffies - start_time)/1000;
-	if ((retry < 2) && (elapsed_time_sec < (mrioc->ready_timeout - 60))) {
+	if (retry < 2 && elapsed_time_sec + 60 < mrioc->ready_timeout) {
 		retry++;
 
 		ioc_warn(mrioc, "retrying to bring IOC ready, retry_count:%d\n"
-- 
2.56.1.750.gf70dc682cf-goog


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-11-20 19:01 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-20 19:00 [PATCH v2 0/3] scsi: mpi3mr: Fix error return, start_time, and timeout check in mpi3mr_bring_ioc_ready() Ian Rogers
2026-11-20 19:00 ` [PATCH v2 1/3] scsi: mpi3mr: Return error on all failure exits " Ian Rogers
2026-11-20 19:00 ` [PATCH v2 2/3] scsi: mpi3mr: Initialize start_time on all paths " Ian Rogers
2026-11-20 19:00 ` [PATCH v2 3/3] scsi: mpi3mr: Avoid ready_timeout underflow " Ian Rogers

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®