public inbox for linux-scsi@vger.kernel.org
 help / color / mirror / Atom feed
From: Bart Van Assche <bvanassche@acm.org>
To: Damien Le Moal <dlemoal@kernel.org>,
	"Martin K . Petersen" <martin.petersen@oracle.com>,
	linux-scsi@vger.kernel.org
Subject: Re: [PATCH v2] scsi: sd: Set a default optimal IO size if one is not defined
Date: Wed, 11 Jun 2025 08:35:29 -0700	[thread overview]
Message-ID: <f1877d65-6b7b-4d71-899d-d6b3d8bafbdc@acm.org> (raw)
In-Reply-To: <20250611122921.3960656-1-dlemoal@kernel.org>

On 6/11/25 5:29 AM, Damien Le Moal wrote:
> +static void sd_set_io_opt(struct scsi_disk *sdkp, unsigned int dev_max,
> +			  struct queue_limits *lim)
> +{
> +	struct scsi_device *sdp = sdkp->device;
> +	struct Scsi_Host *shost = sdp->host;
> +
> +	lim->io_opt = shost->opt_sectors << SECTOR_SHIFT;
> +	if (sd_validate_opt_xfer_size(sdkp, dev_max))
> +		lim->io_opt = min_not_zero(lim->io_opt,
> +				logical_to_bytes(sdp, sdkp->opt_xfer_blocks));
> +	if (!lim->io_opt) {
> +		lim->io_opt = ALIGN_DOWN(lim->max_sectors << SECTOR_SHIFT,
> +					 sdkp->physical_block_size - 1);
> +		sd_first_printk(KERN_INFO, sdkp,
> +			"Using default optimal transfer size of %u bytes\n",
> +			lim->io_opt);
> +	}
> +}

shost->opt_sectors and lim->max_sectors both have type unsigned int so
when shifting these left there is a risk of overflow. As an example,
from the scsi_debug driver:

	.max_sectors =		-1U,

Shouldn't integer overflows be prevented instead of letting these
happen?

Thanks,

Bart.


  reply	other threads:[~2025-06-11 15:35 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-06-11 12:29 [PATCH v2] scsi: sd: Set a default optimal IO size if one is not defined Damien Le Moal
2025-06-11 15:35 ` Bart Van Assche [this message]
2025-06-11 23:09   ` Damien Le Moal

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=f1877d65-6b7b-4d71-899d-d6b3d8bafbdc@acm.org \
    --to=bvanassche@acm.org \
    --cc=dlemoal@kernel.org \
    --cc=linux-scsi@vger.kernel.org \
    --cc=martin.petersen@oracle.com \
    /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