Linux SCSI subsystem development
 help / color / mirror / Atom feed
From: Laurence Oberman <loberman@redhat.com>
To: sashiko-reviews@lists.linux.dev
Cc: linux-scsi@vger.kernel.org
Subject: Re: [PATCH v3 1/4] scsi: st: Restore changed drive settings after reset also for MTLOAD and MTRETEN
Date: Tue, 29 Sep 2026 13:45:19 -0400	[thread overview]
Message-ID: <9a9da14629887529cbdc7efbe5809f19ed140d23.camel@redhat.com> (raw)
In-Reply-To: <20260929173335.0562F1F000FF@smtp.kernel.org>

On Tue, 2026-09-29 at 17:33 +0000, sashiko-bot@kernel.org wrote:
> Thank you for your contribution! Sashiko AI review found 1 potential
> issue(s) to consider:
> - [High] scsi: st: MTLOAD in immediate mode attempts premature
> settings restore
> --
> 
> commit 17d984b3de3a58216a78afa696892ddd4aea0bbd
> Author: Laurence Oberman <loberman@redhat.com>
> 
> scsi: st: Restore changed drive settings after reset also for MTLOAD
> and MTRETEN
> 
> A device reset returns the drive's density and block size to their
> defaults.
> This patch attempts to re-apply values changed by the user when
> recovering
> with MTLOAD or MTRETEN.
> 
> > diff --git a/drivers/scsi/st.c b/drivers/scsi/st.c
> > index f1c3c49466379..0a4263bef9cbb 100644
> > --- a/drivers/scsi/st.c
> > +++ b/drivers/scsi/st.c
> [ ... ]
> > @@ -3819,6 +3848,9 @@ static long st_ioctl(struct file *file,
> > unsigned int cmd_in, unsigned long arg)
> >  
> >  		if (mtc.mt_op == MTLOAD) {
> >  			retval = do_load_unload(STp, file, max(1,
> > mtc.mt_count));
> > +			if (!retval)
> > +				st_restore_changed_settings(STp,
> > restore_density,
> > +							   
> > restore_blksize);
> 
> [Severity: High]
> Does this code attempt a premature settings restore if MTLOAD is
> called
> in immediate mode?
> 
> If a user application issues MTLOAD with O_NONBLOCK and STp-
> >immediate
> set to recover after a drive reset, do_load_unload() will issue the
> load
> command and return immediately. This unconditional call to
> st_restore_changed_settings() would then cause MODE SELECT commands
> to
> fail because the drive is still asynchronously loading.
> 
> Later, when the drive is accessed, check_tape() detects the new
> session
> and clears the changed flags, causing the drive to silently revert to
> its default density and block size. Subsequent writes might then
> produce
> incorrectly formatted tapes without errors.
> 
> For MTRETEN, this patch correctly checks for !STp->immediate before
> restoring
> the settings:
> 
> >  			goto out;
> >  		}
> [ ... ]
> > @@ -3837,6 +3869,19 @@ static long st_ioctl(struct file *file,
> > unsigned int cmd_in, unsigned long arg)
> >  			retval = st_compression(STp, (mtc.mt_count
> > & 1));
> >  		else
> >  			retval = st_int_ioctl(STp, mtc.mt_op,
> > mtc.mt_count);
> > +		if (!retval && mtc.mt_op == MTRETEN && !STp-
> > >immediate &&
> > +		    (restore_density >= 0 || restore_blksize >=
> > 0)) {
> 
> Should MTLOAD also verify !STp->immediate before calling
> st_restore_changed_settings() in st_ioctl()? Note that follow-up
> patches
> in this series do not correct this omission.
> 
> 
Hello Sashiko, 

This only affects MTLOAD in immediate mode with an O_NONBLOCK open;
with a blocking open check_tape() waits for the drive and the restore
works. In the non-blocking case the MODE SELECTs fail and the settings
stay at the drive defaults, which is the current behaviour without the
patch, so it is not a regression. I can add a "STp->ready == ST_READY"
check before the restore in a follow-up and leave v3 as is.

Thanks
Laurence


  reply	other threads:[~2026-09-29 17:45 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-29 17:18 [PATCH v3 0/4] scsi: st: Restore drive settings and state after reset and MTLOAD Laurence Oberman
2026-09-29 17:18 ` [PATCH v3 1/4] scsi: st: Restore changed drive settings after reset also for MTLOAD and MTRETEN Laurence Oberman
2026-09-29 17:33   ` sashiko-bot
2026-09-29 17:45     ` Laurence Oberman [this message]
2026-09-29 17:18 ` [PATCH v3 2/4] scsi: st: Record the tape position after a successful MTLOAD Laurence Oberman
2026-09-29 17:41   ` sashiko-bot
2026-09-29 18:16     ` Laurence Oberman
2026-09-29 17:18 ` [PATCH v3 3/4] scsi: st: Restore the drive buffering mode after reset Laurence Oberman
2026-09-29 17:18 ` [PATCH v3 4/4] scsi: st: Relock the door after a reset Laurence Oberman

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=9a9da14629887529cbdc7efbe5809f19ed140d23.camel@redhat.com \
    --to=loberman@redhat.com \
    --cc=linux-scsi@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox