Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp547901pxf; Thu, 18 Mar 2021 06:53:29 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzMzAakOdkJlVA63RYHmaH+HdmYgFQori6CUqNWYF+jOJKQzU7V17GycvTITyB25J/G/4nY X-Received: by 2002:a17:906:4ada:: with SMTP id u26mr41503466ejt.129.1616075609307; Thu, 18 Mar 2021 06:53:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1616075609; cv=none; d=google.com; s=arc-20160816; b=NeQemXG03yFvv35dH4gykZ+qS45zRwuy5MiOSm5ertp8VmeH7RNFTcQpb61+haOa4c M9d6udVLs2GDjm9sZWg70xyxax4XHHA4Qk7JwmwYtxShaBUs4ng3hsmRISqC3HT+hpjE snAnBoaAgZhSlF5860Ouqc2q4LghZBV64BxQpzceWZEjeTyLUeYU7QWUS0EIre+X/njL 0M4HhTb4LI+haYcrKaPGqFRo3hp6sN+oFsfDNZ6egyjY2m4EPS5gR2V5aQ+EQ23fb88I kyCJ9dTBf26E3jZGuYLCkOQY8riSsDPeYaw0YcDFtev9w+72yp4utPMmhRpPWaynIsjQ TWlQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=mJHY8qu/zb8ROas4WV0ki8PTfXxIvdJCtkC7EQYxU/c=; b=d3/odMWbQK/7QISjV4oaPNGCeBPLKwoPf7dZcUnMSI5GsFhSZsFGOmvPbKvVEgbmNW y4/5vAZm1LsCk/QPp8ARXM1L9UWfKZoqEx1i6kN6rdljr1MjDptt1Zgff4E44/kt49Yw p+AVE5hit7OH1LnW+JWhuBSNZ9r3TIV4Du1LHAjRicBbzu1XpdXiqstS/1uxxmWlg3r7 n+/uPk66ajYFASRzJnZPrVKx29tv7NwfjJmI71c0dhZCUN/fAykKwO25U6SVFMQU/iSW /SGdVYDWa5UcEfIlbviMEQQ2UDdyq6XVjt7zuB4YXR7juUm963HlSJmSgTApEBslDGAc l7/w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=vsx5ftBh; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id 26si1586275ejy.13.2021.03.18.06.53.07; Thu, 18 Mar 2021 06:53:29 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=vsx5ftBh; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230010AbhCRNwK (ORCPT + 99 others); Thu, 18 Mar 2021 09:52:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46426 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229955AbhCRNvs (ORCPT ); Thu, 18 Mar 2021 09:51:48 -0400 Received: from mail-io1-xd2b.google.com (mail-io1-xd2b.google.com [IPv6:2607:f8b0:4864:20::d2b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6A7F8C06174A for ; Thu, 18 Mar 2021 06:51:48 -0700 (PDT) Received: by mail-io1-xd2b.google.com with SMTP id b10so2329947iot.4 for ; Thu, 18 Mar 2021 06:51:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=mJHY8qu/zb8ROas4WV0ki8PTfXxIvdJCtkC7EQYxU/c=; b=vsx5ftBh4NCKMRiay+ZiqQeya0glKxvKsDmSdOqWUoRb42TOuC+fLwbmPkZmzlrrsz /GkGXCjAm+QKtLfOadnSd227TNYl/UwNRb+7pD47UC0tZK3D5jv2qT/Qzm8GEiu8Ufad yJgFFnGNjP5wKbQ+6lI2XtM+v3+GL9Wj9wXWpX/WsKKILECvVCnijnVAxO3EowT80J+J GJxh5vMljJuRCv8uFgbRWBqgt0qQrwpsbrH/LUtXpmsU2IDclabOdyPMsehIT/gmt89e oPKaXdH3BaQ69fCGvVg2+KrzjwefZ3pY07+tAiplVP8QX1V1Hza533VSOBMhy02UNQgL y0FQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=mJHY8qu/zb8ROas4WV0ki8PTfXxIvdJCtkC7EQYxU/c=; b=GEbjkaCF7nqcxdcBdw4xibHkAnF6Yqf2bmafaNKHLax3tV40a/r7IkcNM3sY9F6pkg yC0t48rfgmOC+4ewYA3XtdMcmzzmkmGL75fy65ngZWcb14ZKONeif3bmFgyBPIAGEaKk 8zjjM1bMVtVZMFG5lXXtJIcL1/fmbLGoYwQKQQjOzIjL3lQAZg8C7vzpPhw/KVHciEIY UToPuS+9T4xFsYEwcXaSp7Sv3YPQHZvnlVMQP0coZuYe2OXjgYsO3cuq3KKop3kfYrFD oNBrmzARm3vXEbUbtXJKDuIzZQpLnUuf3UI5wjLbSTL4lZ3d0z9/6kWrXWdWlVb2Kv5f JN4A== X-Gm-Message-State: AOAM53083Pf+ZXmDYs1pyzNjPLomn87wCwifkXZ+szRAGler5euxbitF fXsbvQXe2FsMma/MokZIvKTYiA== X-Received: by 2002:a02:9048:: with SMTP id y8mr6962279jaf.66.1616075507892; Thu, 18 Mar 2021 06:51:47 -0700 (PDT) Received: from localhost.localdomain (c-73-185-129-58.hsd1.mn.comcast.net. [73.185.129.58]) by smtp.gmail.com with ESMTPSA id j20sm1139377ilo.78.2021.03.18.06.51.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 Mar 2021 06:51:47 -0700 (PDT) From: Alex Elder To: davem@davemloft.net, kuba@kernel.org Cc: f.fainelli@gmail.com, 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 Subject: [PATCH net-next v2 3/4] net: ipa: fix table alignment requirement Date: Thu, 18 Mar 2021 08:51:40 -0500 Message-Id: <20210318135141.583977-4-elder@linaro.org> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20210318135141.583977-1-elder@linaro.org> References: <20210318135141.583977-1-elder@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org We currently have a build-time check to ensure that the minimum DMA allocation alignment satisfies the constraint that IPA filter and route tables must point to rules that are 128-byte aligned. But what's really important is that the actual allocated DMA memory has that alignment, even if the minimum is smaller than that. Remove the BUILD_BUG_ON() call checking against minimim DMA alignment and instead verify at rutime that the allocated memory is properly aligned. Signed-off-by: Alex Elder --- drivers/net/ipa/ipa_table.c | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/drivers/net/ipa/ipa_table.c b/drivers/net/ipa/ipa_table.c index dd07fe9dd87a3..988f2c2886b95 100644 --- a/drivers/net/ipa/ipa_table.c +++ b/drivers/net/ipa/ipa_table.c @@ -118,14 +118,6 @@ /* Check things that can be validated at build time. */ static void ipa_table_validate_build(void) { - /* IPA hardware accesses memory 128 bytes at a time. Addresses - * referred to by entries in filter and route tables must be - * aligned on 128-byte byte boundaries. The only rule address - * ever use is the "zero rule", and it's aligned at the base - * of a coherent DMA allocation. - */ - BUILD_BUG_ON(ARCH_DMA_MINALIGN % IPA_TABLE_ALIGN); - /* Filter and route tables contain DMA addresses that refer * to filter or route rules. But the size of a table entry * is 64 bits regardless of what the size of an AP DMA address @@ -665,6 +657,18 @@ int ipa_table_init(struct ipa *ipa) if (!virt) return -ENOMEM; + /* We put the "zero rule" at the base of our table area. The IPA + * hardware requires rules to be aligned on a 128-byte boundary. + * Make sure the allocation satisfies this constraint. + */ + if (addr % IPA_TABLE_ALIGN) { + dev_err(dev, "table address %pad not %u-byte aligned\n", + &addr, IPA_TABLE_ALIGN); + dma_free_coherent(dev, size, virt, addr); + + return -ERANGE; + } + ipa->table_virt = virt; ipa->table_addr = addr; -- 2.27.0