From patchwork Thu Mar 18 18:59:29 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Elder X-Patchwork-Id: 404054 Delivered-To: patch@linaro.org Received: by 2002:a02:8562:0:0:0:0:0 with SMTP id g89csp733512jai; Thu, 18 Mar 2021 12:00:32 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwpiQ0Ha/mm8xJACEZTTzGVok8zPzPVuQGekn4YLbSjvztqWTKZmMWoTIOAueotEHQSW4sS X-Received: by 2002:a05:6402:10c9:: with SMTP id p9mr5493597edu.268.1616094032079; Thu, 18 Mar 2021 12:00:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1616094032; cv=none; d=google.com; s=arc-20160816; b=0V2eQiEjbSWhKK08znVMkratKvS1k3AeUK9lS6YwpUvhgWrO/UIwBTQX4p+IUCsrz8 MDI9lVC1qr9KxUKeNzaHmZCgDVvT3j3U+Ydgi9QrKQSPhy6BXdZgk6m3kJNOJ7W7K0Ir muT4WspmLleE0rG0ddPg3Ye42uCvxrrsZaKN+72gacJ27TTIkDXS+0uXFcjv8//pXmA+ jVDBCF7EjhLg5ns4fsul3izZv1QiThn95JR8EhNVKX+2oA4DV7U/U4wEj8cCtyc+7/lL OEllrP3ej5fQBYUQIKXz0W0Cx15Hpjk1xAJWdYGk4jBv5C0q/cFYMVovzOjTsOilMIz0 nJ7g== 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=mx7quLXsg+5JJ1Absdr1gPHTTNGABOuozzCTanb/TuBDi7j8CTaC4vxXtennuGHvPw Ob7H0njkadJwU94rSqOFOoE2sPMdI4Ccmq/2khLqTMkOk7gHD0QXZRHQGAEvCBRWhsQL ygUJIAdlGqzO9irtq2suSwgn65n/8inDbZq64ICaqi3anVpYd44JRV5ublLKy7FjykPn 4au8AKItR7rns4kIWSlL/tKr758C23xRNdHouPPPZ2caLdowA+Shpd3eKKrSojJVSk8y A9Be5nfC5LY9//3DEeAzwLyVEv+CAo5+XP9ZaPexdkYJeBfTcpR3gZwC4jyyG2vhLR7x ztTA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Q9Wc6Xbb; spf=pass (google.com: domain of netdev-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=netdev-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 u19si2210823edo.583.2021.03.18.12.00.31; Thu, 18 Mar 2021 12:00:32 -0700 (PDT) Received-SPF: pass (google.com: domain of netdev-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=Q9Wc6Xbb; spf=pass (google.com: domain of netdev-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=netdev-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 S232817AbhCRS77 (ORCPT + 8 others); Thu, 18 Mar 2021 14:59:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57380 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232805AbhCRS7h (ORCPT ); Thu, 18 Mar 2021 14:59:37 -0400 Received: from mail-io1-xd36.google.com (mail-io1-xd36.google.com [IPv6:2607:f8b0:4864:20::d36]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 06944C06175F for ; Thu, 18 Mar 2021 11:59:37 -0700 (PDT) Received: by mail-io1-xd36.google.com with SMTP id n198so3436799iod.0 for ; Thu, 18 Mar 2021 11:59:37 -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=Q9Wc6XbbM16YwfxDXr3sNWeSKz5zpvJ0E/Um5exSMglmBlQkVU4K7TDXNRXvmxctG0 bd2x3/DTy7h7opWcMw9wF27cNZXkZ/tVEpg3RBBFDNlw42KNGWuGPqiISn5sNW/tGdx+ fm3F8uOHIP0SqLl+hHNV5VgGSC6nt82g+M+rVRLvnK5pBckYA3DjPBWqNIxwW5C4BlSe gQzRGsmXe8h/9QQIz3HrLnQG4KcNUwngLEiepeEWCN4tWnk2SNEK8yj6MWqYs63kSims qUOuuOOeygYDjxTcJnPR/re3reqGogVna2Tme8PqD3To+2listO5gM3ouIgPdQwdgO/M HfZw== 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=FobSR/vKUkHfLOqaeVRunJj7Md2YFtn5kRiSGVo7O7s0wEP+YbcZBq6uWKvUXeDGPM 9wETkejmcvzkZ/6n4JKQloP+pRuLhJJ7Qpasc1m4fNEH3aL7kMi+Dq5GIG+PyYEbxGSr x7igHQCTjZ6G0/6BMWivraWZ7Hk1kAWNQNzmRkUTTyCMzbJodzIuKu+QtICsES/u9tDP NDf7l5+66C6PlqiBWuyC3Z+Bfec89NQBho94naqFfiCMOxk5sA5rB5Qalvapp2A6TjL6 e4l7a1nJM+wfiWyxikwXY9GDKtCPsVm4k0Z2eZIxrjiEWXDKQvvnQHYxQjfzlw8RPv7l i0mw== X-Gm-Message-State: AOAM533pfNk9TbjwGlmOC+d4j0nI1iU0YeQsILOVzCyvjRlqf2OCVaHv uZGH+4WPve0ZSM8TEISAqcXTEQ== X-Received: by 2002:a5d:8707:: with SMTP id u7mr44175iom.18.1616093976458; Thu, 18 Mar 2021 11:59:36 -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 k7sm770359ils.35.2021.03.18.11.59.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 Mar 2021 11:59:36 -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 v3 3/4] net: ipa: fix table alignment requirement Date: Thu, 18 Mar 2021 13:59:29 -0500 Message-Id: <20210318185930.891260-4-elder@linaro.org> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20210318185930.891260-1-elder@linaro.org> References: <20210318185930.891260-1-elder@linaro.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@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(-) -- 2.27.0 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;