[lvc-project] [PATCH] scsi: fix calculation of phy_addr in mvumi_delete_internal_cmd

Fedor Pchelkin pchelkin at ispras.ru
Sat Mar 16 19:07:42 MSK 2024


On Sat, 16. Dec 21:50, Rand Deeb wrote:
> The calculation of phy_addr in mvumi_delete_internal_cmd contained an issue
> where the expression '(dma_addr_t) ((m_sg->baseaddr_h << 16) << 16)' was used.
> This expression was found to be incorrect and useless because it always evaluates
> to zero, regardless of the actual value of m_sg->baseaddr_h since it's u32.
> 
> This commit resolves the issue by placing the casting inside the brackets, making it
> more meaningful: (((dma_addr_t) m_sg->baseaddr_h << 16) << 16)
> 
> The corrected expression ensures that phy_addr is calculated correctly and
> addresses the previous issue, preventing the unnecessary use of a zero value.
> 
> Found by Linux Verification Center (linuxtesting.org) with SVACE.
> 
> Signed-off-by: Rand Deeb <rand.sec96 at gmail.com>

Спасибо за патч, Ранд!

Добавлено в ветки linux-5.10-lvc-next и linux-6.1-lvc-next с тегом
`Fixes: f0c568a478f0 ("[SCSI] mvumi: Add Marvell UMI driver")`, так как патч
исправляет достаточно серьезную потенциальную ошибку.

Скорее всего, этот драйвер и устройство обходятся нижними 32 битами
DMA-адреса - это обеспечивает функция dma_alloc_coherent() по умолчанию [1].
Поэтому он наверно в принципе функционирует и не падает при удалении
внутренней команды, если бы действительно использовались все 64 бита.

Явного требования [1] использовать все 64 бита с помощью функции
dma_set_coherent_mask() в драйвере, насколько вижу, нет. И тем не менее,
драйвер различает верхние и нижнии 32 бита адреса, интересно почему.

[1]: https://docs.kernel.org/core-api/dma-api-howto.html#using-consistent-dma-mappings

> ---
>  drivers/scsi/mvumi.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/scsi/mvumi.c b/drivers/scsi/mvumi.c
> index 0354898d7cac..675ea5dcaa21 100644
> --- a/drivers/scsi/mvumi.c
> +++ b/drivers/scsi/mvumi.c
> @@ -296,7 +296,7 @@ static void mvumi_delete_internal_cmd(struct mvumi_hba *mhba,
>  			sgd_getsz(mhba, m_sg, size);
>  
>  			phy_addr = (dma_addr_t) m_sg->baseaddr_l |
> -				(dma_addr_t) ((m_sg->baseaddr_h << 16) << 16);
> +				(((dma_addr_t) m_sg->baseaddr_h << 16) << 16);
>  
>  			dma_free_coherent(&mhba->pdev->dev, size, cmd->data_buf,
>  								phy_addr);
> -- 
> 2.34.1
> 



More information about the lvc-project mailing list