From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 915A8C433F5 for ; Wed, 20 Oct 2021 10:51:11 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 56F8860F22 for ; Wed, 20 Oct 2021 10:51:11 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 56F8860F22 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=foss.st.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:Content-Type: Content-Transfer-Encoding:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:Date:Message-ID:From: References:CC:To:Subject:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=7aXZyyyuVwsSezi0pejd7aaxpbigrxzixE4hwgUdA1s=; b=ean+bD04AG9+MCEb+V0eLijezN k4tfflvesYya0Ys1XHDZWtIAOOhkHg9cIqRJERLD4GlWIcCy5tHgNJ71mu+HeLTeVbJTvocJ3j6OW Wtr/TARjBUFok8IXU08OPWL6cdp54M7mKrAaTX+Ii8KFB4genDIT0DeBZhaMeruiL3JSJeI8fDruh tGfN8SvEn6JnHVdyUGZWmX74S7VpXWnOqyUp3ZKkMaXONkwvsVVfafU6X+Rw7FuWQbK2bjXbk3yNx WV6EBEziEgKIpHQF4oFg1hLTW9d1Z6P3BJd9cSbngl8imV0S1MWf9whSZuieZy7Jbg6o2k0c7cOQg oBaRNLxg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1md99a-004BZa-6O; Wed, 20 Oct 2021 10:49:04 +0000 Received: from mx08-00178001.pphosted.com ([91.207.212.93] helo=mx07-00178001.pphosted.com) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1md962-004Ai4-Cs for linux-arm-kernel@lists.infradead.org; Wed, 20 Oct 2021 10:45:24 +0000 Received: from pps.filterd (m0046661.ppops.net [127.0.0.1]) by mx07-00178001.pphosted.com (8.16.1.2/8.16.1.2) with SMTP id 19KAOVfX018155; Wed, 20 Oct 2021 12:45:07 +0200 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=foss.st.com; h=subject : to : cc : references : from : message-id : date : mime-version : in-reply-to : content-type : content-transfer-encoding; s=selector1; bh=MlxYuucZ3hZA3qvuKEJnxNhi1CYH/kqnrHAjiFr79Po=; b=Hs14Rn5RB7KO632z6fryOsvT+wyNnBwekph0ayCGJavFI4brgsuQ/2llb3Af1xqPod9m w9q74e18eoN60W8CH2UsOps2rZ3uyl8Q+sIwgJuM/vbDSq1dSyaO6LQ7kF1GmbYgQLe2 4DrBYgmIpYEXgikLK81erL5nuwDWObAWDLrf46lrVd+72X9rBEgGqWCMQRvbE5IhZQE7 XEZ4Yqn4upavnnEK8kggCO443cnP5UZtu9E0ebURc9oXqiUMwICpQHLLlu4MZ7lvul4d 2M7YXGceErpGogWh3jKSq9Mbo/lyVdO4cqShCzkDvlFMa+h9fNuPYm7Tsl0vuLGI89xH FQ== Received: from beta.dmz-eu.st.com (beta.dmz-eu.st.com [164.129.1.35]) by mx07-00178001.pphosted.com with ESMTP id 3btdkya26d-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 20 Oct 2021 12:45:07 +0200 Received: from euls16034.sgp.st.com (euls16034.sgp.st.com [10.75.44.20]) by beta.dmz-eu.st.com (STMicroelectronics) with ESMTP id 7833710002A; Wed, 20 Oct 2021 12:45:05 +0200 (CEST) Received: from Webmail-eu.st.com (sfhdag2node2.st.com [10.75.127.5]) by euls16034.sgp.st.com (STMicroelectronics) with ESMTP id 6A46A21A230; Wed, 20 Oct 2021 12:45:05 +0200 (CEST) Received: from lmecxl0995.lme.st.com (10.75.127.50) by SFHDAG2NODE2.st.com (10.75.127.5) with Microsoft SMTP Server (TLS) id 15.0.1497.18; Wed, 20 Oct 2021 12:45:04 +0200 Subject: Re: [PATCH] dmaengine: stm32-dma: avoid 64-bit division in stm32_dma_get_max_width To: Arnd Bergmann , Vinod Koul , Maxime Coquelin , Alexandre Torgue CC: Arnd Bergmann , Zhang Qilong , , , , References: <20211019153532.366429-1-arnd@kernel.org> From: Amelie DELAUNAY Message-ID: Date: Wed, 20 Oct 2021 12:45:03 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.13.0 MIME-Version: 1.0 In-Reply-To: <20211019153532.366429-1-arnd@kernel.org> Content-Language: en-US X-Originating-IP: [10.75.127.50] X-ClientProxiedBy: SFHDAG2NODE1.st.com (10.75.127.4) To SFHDAG2NODE2.st.com (10.75.127.5) X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.182.1,Aquarius:18.0.790,Hydra:6.0.425,FMLib:17.0.607.475 definitions=2021-10-20_04,2021-10-20_01,2020-04-07_01 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211020_034522_936977_78213813 X-CRM114-Status: GOOD ( 32.73 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="us-ascii"; Format="flowed" Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Hi Arnd, Thanks for your patch. On 10/19/21 5:35 PM, Arnd Bergmann wrote: > From: Arnd Bergmann > > Using the % operator on a 64-bit variable is expensive and can > cause a link failure: > > arm-linux-gnueabi-ld: drivers/dma/stm32-dma.o: in function `stm32_dma_get_max_width': > stm32-dma.c:(.text+0x170): undefined reference to `__aeabi_uldivmod' > arm-linux-gnueabi-ld: drivers/dma/stm32-dma.o: in function `stm32_dma_set_xfer_param': > stm32-dma.c:(.text+0x1cd4): undefined reference to `__aeabi_uldivmod' > > As we know that we just want to check the alignment in > stm32_dma_get_max_width(), there is no need for a full division, and > using a simple mask is a faster replacement. > > In stm32_dma_set_xfer_param(), it is possible to pass a non-power-of-two > length, so this does not work. I assume this would in fact be a mistake, > and the hardware does not work correctly with a burst of e.g. 5 bytes > on a five-byte aligned address. Change this to only allow burst > transfers if the address is a multiple of the length, and that length > is a power-of-two number. > > Fixes: b20fd5fa310c ("dmaengine: stm32-dma: fix stm32_dma_get_max_width") > Signed-off-by: Arnd Bergmann > --- > drivers/dma/stm32-dma.c | 6 +++--- > 1 file changed, 3 insertions(+), 3 deletions(-) > > diff --git a/drivers/dma/stm32-dma.c b/drivers/dma/stm32-dma.c > index 2283c500f4ce..102278f7d13e 100644 > --- a/drivers/dma/stm32-dma.c > +++ b/drivers/dma/stm32-dma.c > @@ -280,7 +280,7 @@ static enum dma_slave_buswidth stm32_dma_get_max_width(u32 buf_len, > max_width > DMA_SLAVE_BUSWIDTH_1_BYTE) > max_width = max_width >> 1; > > - if (buf_addr % max_width) > + if (buf_addr & (max_width - 1)) > max_width = DMA_SLAVE_BUSWIDTH_1_BYTE; > > return max_width; > @@ -757,7 +757,7 @@ static int stm32_dma_set_xfer_param(struct stm32_dma_chan *chan, > * Set memory burst size - burst not possible if address is not aligned on > * the address boundary equal to the size of the transfer > */ > - if (buf_addr % buf_len) > + if (!is_power_of_2(buf_len) || (buf_addr & (buf_len -1))) No need to check !is_power_of_2(buf_len) here. Just after computing src_maxburst, src_best_burst = stm32_dma_get_best_burst(buf_len, src_maxburst, fifoth, src_addr_width); The configured burst (src_best_best) already take buf_len into account. So I would remove !is_power_of_2(buf_len) from the if here and fix the missing space: CHECK: spaces preferred around that '-' (ctx:WxV) #68: FILE: drivers/dma/stm32-dma.c:760: + if (!is_power_of_2(buf_len) || (buf_addr & (buf_len -1))) ^ > src_maxburst = 1; > else > src_maxburst = STM32_DMA_MAX_BURST; > @@ -813,7 +813,7 @@ static int stm32_dma_set_xfer_param(struct stm32_dma_chan *chan, > * Set memory burst size - burst not possible if address is not aligned on > * the address boundary equal to the size of the transfer > */ > - if (buf_addr % buf_len) > + if (!is_power_of_2(buf_len) || (buf_addr & (buf_len -1))) Ditto. > dst_maxburst = 1; > else > dst_maxburst = STM32_DMA_MAX_BURST; > With these fixes, you can add my Reviewed-by: Amelie Delaunay Tested-by: Amelie Delaunay Regards, Amelie _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel