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 X-Spam-Level: X-Spam-Status: No, score=-17.5 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,NICE_REPLY_A, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 99AB1C433E1 for ; Wed, 24 Mar 2021 17:11:13 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5FEF461A1D for ; Wed, 24 Mar 2021 17:11:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237252AbhCXRKu (ORCPT ); Wed, 24 Mar 2021 13:10:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56326 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237495AbhCXRJ5 (ORCPT ); Wed, 24 Mar 2021 13:09:57 -0400 Received: from mail-il1-x12e.google.com (mail-il1-x12e.google.com [IPv6:2607:f8b0:4864:20::12e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D9CA5C0613BF for ; Wed, 24 Mar 2021 10:07:30 -0700 (PDT) Received: by mail-il1-x12e.google.com with SMTP id d2so22022206ilm.10 for ; Wed, 24 Mar 2021 10:07:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ieee.org; s=google; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=6DN4TKzVMHLbsDci9dBkcAM0aIpThQJXNnWpGIAbGlM=; b=BixSbChJOh7tqog1NiBEy4XpTXU6z9qabBOn5XKDd7Czp9PiUljcH1qXqlqbpKf+JF XZIRk9ivLe/yUNcr6LVZm8lXXEH/EpJrozLd31E/6vlRmOZ5ZDTNNPkMUv25vJHz2jSv 3x0DowRa9c95sAvOKHrqNK6822AJ7Tv95nou0= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=6DN4TKzVMHLbsDci9dBkcAM0aIpThQJXNnWpGIAbGlM=; b=oJ40ycmCSqJQf20yY7lxvXWuOqwyUV6yf7bKK7mopu2Rb1AiLlVK85u1TLvjfhvNWh W5F+m5VJMrYkdgy4fUN9H/DZqZOoD5AIf6VNIuTAlTldWRxIi7BKOLXlI14HWLhYegkn SPsrywaNFktc9cDmckSQJrTsrMNFurrg2IulFAkln9Xm+eox1X0XenX8gm1oBhFX+/Cj bY7NPemCEMFFng/S4EYPXcaoCpVFz+FRAgohAHW3cgQnJOh1Aa7LXsAzQZbbCXkOfWa0 u+mtMbMBhE3PBA0SD7gy9AkeHoNas5PHCB/+eGHOVFCDGOoYd7jLz63WP1gQbFPpo9G8 uUtQ== X-Gm-Message-State: AOAM5320K048PY3vc6nm3bWKO1BUx9GnpsVk7BESGpCDIz97R8GIDE+a kUOEHxc28jGed41KQ7vKQX3a3F3ZNd3ZJy6T X-Google-Smtp-Source: ABdhPJzDRxca/4uFW98J12ak5RJBZNSQHUArVAUJUITgtcSHarjY3f9d+lWcBAL4Lnw9XFwMWbOVxQ== X-Received: by 2002:a05:6e02:4b2:: with SMTP id e18mr2777811ils.42.1616605649783; Wed, 24 Mar 2021 10:07:29 -0700 (PDT) Received: from [172.22.22.4] (c-73-185-129-58.hsd1.mn.comcast.net. [73.185.129.58]) by smtp.googlemail.com with ESMTPSA id b15sm1390660ilm.25.2021.03.24.10.07.28 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 24 Mar 2021 10:07:28 -0700 (PDT) Subject: Re: [PATCH net-next] net: ipa: avoid 64-bit modulus To: David Laight , 'Alex Elder' , "davem@davemloft.net" , "kuba@kernel.org" Cc: "rdunlap@infradead.org" , "bjorn.andersson@linaro.org" , "evgreen@chromium.org" , "cpratapa@codeaurora.org" , "subashab@codeaurora.org" , "elder@kernel.org" , "netdev@vger.kernel.org" , "linux-kernel@vger.kernel.org" References: <20210323010505.2149882-1-elder@linaro.org> From: Alex Elder Message-ID: Date: Wed, 24 Mar 2021 12:07:27 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.7.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 3/24/21 11:27 AM, David Laight wrote: > 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 >> Signed-off-by: Alex Elder >> --- >> 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? I normally wouldn't check something like this if it weren't guaranteed. I'm not sure why I did it here. I see it's "guaranteed to be aligned to the smallest PAGE_SIZE order which is greater than or equal to the requested size." So I think the answer to your question is "yes, it does guarantee that." I'll make a note to remove this check in a future patch, and will credit you with the suggestion. Thanks. -Alex > > David > > - > Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK > Registration No: 1397386 (Wales) >