Re: [PATCH v4] scsi: sas: skip opt_sectors when DMA reports no real optimization hint

From: James Bottomley

Date: Thu Mar 19 2026 - 17:04:34 EST


On Thu, 2026-03-19 at 22:43 +0200, Ionut Nechita (Wind River) wrote:
> On Wed, 19 Mar 2026 11:07:00 +0000, Damien Le Moal wrote:
> > Why return 0 ? This is a valid case, so this should get through the
> > alignment below.
>
> Hi Damien,
>
> Thanks for the review.
>
> The opt == max case is specifically the bug this patch fixes.
>
> When the IOMMU is disabled or in passthrough mode and no DMA ops
> provide an opt_mapping_size callback, dma_opt_mapping_size() falls
> back to min(SIZE_MAX, dma_max_mapping_size()), which equals
> dma_max_mapping_size().  So opt == max.
>
> If we let that value through, rounddown_pow_of_two() produces a
> huge power-of-two, and min_t() caps it at max_sectors (32767).
> That gives opt_sectors = 32767, which is exactly the bogus value
> that breaks mkfs.xfs:
>
>   swidth = 16773120 / 4096 = 4095
>   sunit  = 8192 / 4096     = 2
>   4095 % 2 != 0  ->  "SB stripe unit sanity check failed"

So if max_sectors is usually 32767 and this breaks xfs why the final
line:

> + return min_t(unsigned int, opt >> SECTOR_SHIFT,
> max_sectors);

because there are surely situations where the above max_sectors
(32767) comes back as the minimum or are you assuming opt >>
SECTOR_SHIFT is always less than max_sectors, in which case there's no
need for min_t?

Additionally, I note that the new AI code review:

https://sashiko.dev/#/patchset/20260319083954.21056-1-ionut.nechita%40windriver.com

Worries that if opt comes back as its don't care zero value then
rounddown_pow_of_2(opt) returns a bogus value.

Regards,

James