mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: David Laight <David.Laight@ACULAB.COM>
To: 'Alex Elder' <elder@linaro.org>,
	"davem@davemloft.net" <davem@davemloft.net>,
	"kuba@kernel.org" <kuba@kernel.org>
Cc: "rdunlap@infradead.org" <rdunlap@infradead.org>,
	"bjorn.andersson@linaro.org" <bjorn.andersson@linaro.org>,
	"evgreen@chromium.org" <evgreen@chromium.org>,
	"cpratapa@codeaurora.org" <cpratapa@codeaurora.org>,
	"subashab@codeaurora.org" <subashab@codeaurora.org>,
	"elder@kernel.org" <elder@kernel.org>,
	"netdev@vger.kernel.org" <netdev@vger.kernel.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: RE: [PATCH net-next] net: ipa: avoid 64-bit modulus
Date: Wed, 24 Mar 2021 16:27:09 +0000	[thread overview]
Message-ID: <f77f12f117934e9d9e3b284ed37e87a7@AcuMS.aculab.com> (raw)
In-Reply-To: <20210323010505.2149882-1-elder@linaro.org>

From: Alex Elder
> Sent: 23 March 2021 01:05
> It is possible for a 32 bit x86 build to use a 64 bit DMA address.
> 
> There are two remaining spots where the IPA driver does a modulo
> operation to check alignment of a DMA address, and under certain
> conditions this can lead to a build error on i386 (at least).
> 
> The alignment checks we're doing are for power-of-2 values, and this
> means the lower 32 bits of the DMA address can be used.  This ensures
> both operands to the modulo operator are 32 bits wide.
> 
> Reported-by: Randy Dunlap <rdunlap@infradead.org>
> Signed-off-by: Alex Elder <elder@linaro.org>
> ---
>  drivers/net/ipa/gsi.c       | 11 +++++++----
>  drivers/net/ipa/ipa_table.c |  9 ++++++---
>  2 files changed, 13 insertions(+), 7 deletions(-)
> 
> diff --git a/drivers/net/ipa/gsi.c b/drivers/net/ipa/gsi.c
> index 7f3e338ca7a72..b6355827bf900 100644
> --- a/drivers/net/ipa/gsi.c
> +++ b/drivers/net/ipa/gsi.c
> @@ -1436,15 +1436,18 @@ static void gsi_evt_ring_rx_update(struct gsi_evt_ring *evt_ring, u32 index)
>  /* Initialize a ring, including allocating DMA memory for its entries */
>  static int gsi_ring_alloc(struct gsi *gsi, struct gsi_ring *ring, u32 count)
>  {
> -	size_t size = count * GSI_RING_ELEMENT_SIZE;
> +	u32 size = count * GSI_RING_ELEMENT_SIZE;
>  	struct device *dev = gsi->dev;
>  	dma_addr_t addr;
> 
> -	/* Hardware requires a 2^n ring size, with alignment equal to size */
> +	/* Hardware requires a 2^n ring size, with alignment equal to size.
> +	 * The size is a power of 2, so we can check alignment using just
> +	 * the bottom 32 bits for a DMA address of any size.
> +	 */
>  	ring->virt = dma_alloc_coherent(dev, size, &addr, GFP_KERNEL);

Doesn't dma_alloc_coherent() guarantee that alignment?
I doubt anywhere else checks?

	David

-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)


  parent reply	other threads:[~2021-03-24 16:27 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-23  1:05 Alex Elder
2021-03-23  2:44 ` Randy Dunlap
2021-03-24  0:20 ` patchwork-bot+netdevbpf
2021-03-24 16:27 ` David Laight [this message]
2021-03-24 17:07   ` Alex Elder
2021-03-24 17:12     ` David Laight
2021-03-24 17:32       ` Alex Elder

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=f77f12f117934e9d9e3b284ed37e87a7@AcuMS.aculab.com \
    --to=david.laight@aculab.com \
    --cc=bjorn.andersson@linaro.org \
    --cc=cpratapa@codeaurora.org \
    --cc=davem@davemloft.net \
    --cc=elder@kernel.org \
    --cc=elder@linaro.org \
    --cc=evgreen@chromium.org \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=rdunlap@infradead.org \
    --cc=subashab@codeaurora.org \
    /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

all inboxes | Powered by JetHome®