public inbox for linux-scsi@vger.kernel.org
 help / color / mirror / Atom feed
From: Damien Le Moal <dlemoal@kernel.org>
To: Bart Van Assche <bvanassche@acm.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: Thu, 12 Jun 2025 08:09:33 +0900	[thread overview]
Message-ID: <ad209d00-91c9-4d59-a47a-2ece8552bc01@kernel.org> (raw)
In-Reply-To: <f1877d65-6b7b-4d71-899d-d6b3d8bafbdc@acm.org>

On 6/12/25 00:35, Bart Van Assche wrote:
> 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,

The code already was like that for opt_sectors and no-one complained.

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

Sure, can do that.


-- 
Damien Le Moal
Western Digital Research

      reply	other threads:[~2025-06-11 23:09 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
2025-06-11 23:09   ` Damien Le Moal [this message]

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=ad209d00-91c9-4d59-a47a-2ece8552bc01@kernel.org \
    --to=dlemoal@kernel.org \
    --cc=bvanassche@acm.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