Re: [PATCH v7 1/1] scsi: sas: skip opt_sectors when DMA reports no real optimization hint
From: Christoph Hellwig
Date: Fri Apr 24 2026 - 09:21:33 EST
On Wed, Apr 15, 2026 at 10:18:49AM +0300, Ionut Nechita (Wind River) wrote:
> +/*
> + * Set shost->opt_sectors from the DMA optimal mapping size, but only
> + * when dma_opt_mapping_size() is strictly less than dma_max_mapping_size(),
> + * indicating a genuine optimization hint from an IOMMU or DMA backend.
> + * When the two are equal (e.g. IOMMU disabled / passthrough), no real
> + * hint exists, so leave opt_sectors at 0 to avoid bogus optimal_io_size
> + * values that break filesystem geometry (e.g. mkfs.xfs stripe alignment).
> + */
> +static void sas_dma_setup_opt_sectors(struct Scsi_Host *shost)
> +{
> + struct device *dma_dev = shost->dma_dev;
> + size_t opt, max;
> + unsigned int opt_sectors;
> +
> + if (!dma_dev->dma_mask)
> + return;
Upper layers have no real busines looking at dma_dev->dma_mask. What
is this check intended to do?
> +
> + opt = dma_opt_mapping_size(dma_dev);
> + max = dma_max_mapping_size(dma_dev);
> +
> + if (opt >= max)
> + return;
> +
> + opt_sectors = min_t(unsigned int, opt >> SECTOR_SHIFT,
> + shost->max_sectors);
> + if (!opt_sectors)
> + return;
> +
> + shost->opt_sectors = rounddown_pow_of_two(opt_sectors);
Please add comments explaining the logic.