From patchwork Mon Jul 26 17:40:07 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Elder X-Patchwork-Id: 485856 Delivered-To: patch@linaro.org Received: by 2002:a02:c94a:0:0:0:0:0 with SMTP id u10csp4042452jao; Mon, 26 Jul 2021 10:40:36 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwqE/ROkf7C6k6GBsTSHAXw98S71x1m+qw5lctbGVuz4cFzIr6AwuxJ8h7jzKI69SQlanJa X-Received: by 2002:aa7:c58e:: with SMTP id g14mr23591162edq.210.1627321236296; Mon, 26 Jul 2021 10:40:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1627321236; cv=none; d=google.com; s=arc-20160816; b=POqQhaz8QOQxNtdcQtCSPUJ1oOf9kSRS2G6SElarOKh/+DFWYKO+hzwu4SDhD8hbJx vweupymtKL8m5TZDxN++1Rm09KQ/tRy/GieSVxwY6vcSVEYa+ZXBcd3IraS2dnlE0o8F Sigqtiz34PbpaEpW9/mcReYln0P1AvkG0xAIGLXoCoowvQNIeGeuKRj7RsXnnFan64eX t/H5+Go8KJVH1lf1qc1bcZ+g3TdMvu5yglIWCmQQkPskg8iPyo9DcYxukMVxMjrzZ4dY SnJJ4RKqUVi86/cgcvBU75ZeSRmBBcC0RnyzUwE4Ujp8zVZi3bqivHzRnpxtaCf8Ba4G kLbg== 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=7lEqg3TOKz14G7O++U3GKk3SokkJPyKbuqy0/ExBt4k=; b=H6YHlCAwxW7ZuQLN0vaiaAb5DWWgct8P0Hoop6cIsHZOlIZU7sAYEkNWiVXk+YcuLV WOrPKNCj+6PKTaZS8jG1qL37slJe33ARh/+u6+ihn8ZLYhN+pjmDjLicX52sPWKpvL7N BZLJE2ZFvgijzdw9Gq06m8539Hy66uY1Fxsw9ugQiLUpvUIfJE1Grrf6Br5IAeJzT6Vh odLpIheCb3ZZPb1StsVxpBwqjmbRrFwMyAYpYJJz6F1ML6L2bC9smo3Ew6FiYPlgUDIh OfEjFny3r95Dv7yKadaCPUehl+5RGqnXhpyhukJTNfbSQYllFKLmff+j5U3pbnrbKR5A 7Czw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=LCAMM+Az; 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 o16si534687ejh.496.2021.07.26.10.40.36; Mon, 26 Jul 2021 10:40:36 -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=LCAMM+Az; 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 S231190AbhGZQ7x (ORCPT + 8 others); Mon, 26 Jul 2021 12:59:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45362 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230488AbhGZQ7r (ORCPT ); Mon, 26 Jul 2021 12:59:47 -0400 Received: from mail-il1-x129.google.com (mail-il1-x129.google.com [IPv6:2607:f8b0:4864:20::129]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2BE89C061765 for ; Mon, 26 Jul 2021 10:40:15 -0700 (PDT) Received: by mail-il1-x129.google.com with SMTP id l11so9751218iln.4 for ; Mon, 26 Jul 2021 10:40:15 -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=7lEqg3TOKz14G7O++U3GKk3SokkJPyKbuqy0/ExBt4k=; b=LCAMM+Az3vCW4kU8XKuOsy1mQJVeGS58zmXuWZtImcD6yxBwsdn2gV6yfPPVO6pVSn rxPZLs+CnTGMMkEnMTpsvmOr8Tmkx7vejD3LcxntRfDzDmfvL/liQVH6Dyc0cEWLw8F3 6Qv3+NXscFltuJX/oCVx4dR/a2XITK/rhBk52Ft43nqVa6tlq+GYpywLa+LKDlXNQ2Jt YIURNAP07sU5YRbQCQQrWw0UXAILYKp9Vf0FV1WThYSvzZIdfKjqi+CY+ClTbtb8Nacz jKBbkCzg5xgZYMLaCwSwgHuRqhudQKDvEuBZdJQYG82wN3DYqqhS7lHwnZ6dSl06pJqh h0PA== 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=7lEqg3TOKz14G7O++U3GKk3SokkJPyKbuqy0/ExBt4k=; b=GLw7h0BjkfNGfmcEY9KAjmT9dhxxBFSDa1kSZ909tvtT4OG6pR2hyT8rIERDeIBWiU e33iMCc8BLpy/0+rXI8FlxY3Rhx4Odrg56xJjoungvZfSem2ACjZu8CiET5hnHpDorB8 e5K1CTSQhJfLucqcm6R+gKvFVFitk+gmeWgx6MCpQmUufAf/rPV0oVD/aj/cV/gVKTLS RIJQs8ygnjUP0omNfq0T41AeVX9CTRdj9mRrwK4kAYh/RnoEPlyzAgKpwn0xGdkvHlMJ 4XQFt2fqt+JHtNSZwlG4PZ9CF1ir7cbNZWopgRg0G5tFI0UogzLUG/pC2/1U55y6pVrB y82Q== X-Gm-Message-State: AOAM532/patSe0jg1aY+OlGjGYQMFblkfQ51fjMhVyEFAhetqczsYIeF TyElshS1bg+64Mo/QPw/2eQk8w== X-Received: by 2002:a05:6e02:12ab:: with SMTP id f11mr14040422ilr.200.1627321214611; Mon, 26 Jul 2021 10:40:14 -0700 (PDT) Received: from presto.localdomain (c-73-185-129-58.hsd1.mn.comcast.net. [73.185.129.58]) by smtp.gmail.com with ESMTPSA id l4sm202721ilh.41.2021.07.26.10.40.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Jul 2021 10:40:14 -0700 (PDT) From: Alex Elder To: davem@davemloft.net, kuba@kernel.org Cc: leon@kernel.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 Subject: [PATCH net-next 1/4] net: ipa: fix ipa_cmd_table_valid() Date: Mon, 26 Jul 2021 12:40:07 -0500 Message-Id: <20210726174010.396765-2-elder@linaro.org> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20210726174010.396765-1-elder@linaro.org> References: <20210726174010.396765-1-elder@linaro.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Stop supporting different sizes for hashed and non-hashed filter or route tables. Add BUILD_BUG_ON() calls to verify the sizes of the fields in the filter/route table initialization immediate command are the same. Add a check to ipa_cmd_table_valid() to ensure the size of the memory region being checked fits within the immediate command field that must hold it. Remove two Boolean parameters used only for error reporting. This actually fixes a bug that would only show up if IPA_VALIDATE were defined. Define ipa_cmd_table_valid() unconditionally (no longer dependent on IPA_VALIDATE). Signed-off-by: Alex Elder --- drivers/net/ipa/ipa_cmd.c | 38 ++++++++++++++++++++++++------------- drivers/net/ipa/ipa_cmd.h | 15 +++------------ drivers/net/ipa/ipa_table.c | 2 +- 3 files changed, 29 insertions(+), 26 deletions(-) -- 2.27.0 diff --git a/drivers/net/ipa/ipa_cmd.c b/drivers/net/ipa/ipa_cmd.c index af44ca41189e3..bda8677eae88d 100644 --- a/drivers/net/ipa/ipa_cmd.c +++ b/drivers/net/ipa/ipa_cmd.c @@ -159,35 +159,45 @@ static void ipa_cmd_validate_build(void) BUILD_BUG_ON(TABLE_SIZE > field_max(IP_FLTRT_FLAGS_NHASH_SIZE_FMASK)); #undef TABLE_COUNT_MAX #undef TABLE_SIZE -} -#ifdef IPA_VALIDATE + /* Hashed and non-hashed fields are assumed to be the same size */ + BUILD_BUG_ON(field_max(IP_FLTRT_FLAGS_HASH_SIZE_FMASK) != + field_max(IP_FLTRT_FLAGS_NHASH_SIZE_FMASK)); + BUILD_BUG_ON(field_max(IP_FLTRT_FLAGS_HASH_ADDR_FMASK) != + field_max(IP_FLTRT_FLAGS_NHASH_ADDR_FMASK)); +} /* Validate a memory region holding a table */ -bool ipa_cmd_table_valid(struct ipa *ipa, const struct ipa_mem *mem, - bool route, bool ipv6, bool hashed) +bool ipa_cmd_table_valid(struct ipa *ipa, const struct ipa_mem *mem, bool route) { + u32 offset_max = field_max(IP_FLTRT_FLAGS_NHASH_ADDR_FMASK); + u32 size_max = field_max(IP_FLTRT_FLAGS_NHASH_SIZE_FMASK); + const char *table = route ? "route" : "filter"; struct device *dev = &ipa->pdev->dev; - u32 offset_max; - offset_max = hashed ? field_max(IP_FLTRT_FLAGS_HASH_ADDR_FMASK) - : field_max(IP_FLTRT_FLAGS_NHASH_ADDR_FMASK); + /* Size must fit in the immediate command field that holds it */ + if (mem->size > size_max) { + dev_err(dev, "%s table region size too large\n", table); + dev_err(dev, " (0x%04x > 0x%04x)\n", + mem->size, size_max); + + return false; + } + + /* Offset must fit in the immediate command field that holds it */ if (mem->offset > offset_max || ipa->mem_offset > offset_max - mem->offset) { - dev_err(dev, "IPv%c %s%s table region offset too large\n", - ipv6 ? '6' : '4', hashed ? "hashed " : "", - route ? "route" : "filter"); + dev_err(dev, "%s table region offset too large\n", table); dev_err(dev, " (0x%04x + 0x%04x > 0x%04x)\n", ipa->mem_offset, mem->offset, offset_max); return false; } + /* Entire memory range must fit within IPA-local memory */ if (mem->offset > ipa->mem_size || mem->size > ipa->mem_size - mem->offset) { - dev_err(dev, "IPv%c %s%s table region out of range\n", - ipv6 ? '6' : '4', hashed ? "hashed " : "", - route ? "route" : "filter"); + dev_err(dev, "%s table region out of range\n", table); dev_err(dev, " (0x%04x + 0x%04x > 0x%04x)\n", mem->offset, mem->size, ipa->mem_size); @@ -197,6 +207,8 @@ bool ipa_cmd_table_valid(struct ipa *ipa, const struct ipa_mem *mem, return true; } +#ifdef IPA_VALIDATE + /* Validate the memory region that holds headers */ static bool ipa_cmd_header_valid(struct ipa *ipa) { diff --git a/drivers/net/ipa/ipa_cmd.h b/drivers/net/ipa/ipa_cmd.h index b99262281f41c..ea723419c826b 100644 --- a/drivers/net/ipa/ipa_cmd.h +++ b/drivers/net/ipa/ipa_cmd.h @@ -57,20 +57,18 @@ struct ipa_cmd_info { enum dma_data_direction direction; }; -#ifdef IPA_VALIDATE - /** * ipa_cmd_table_valid() - Validate a memory region holding a table * @ipa: - IPA pointer * @mem: - IPA memory region descriptor * @route: - Whether the region holds a route or filter table - * @ipv6: - Whether the table is for IPv6 or IPv4 - * @hashed: - Whether the table is hashed or non-hashed * * Return: true if region is valid, false otherwise */ bool ipa_cmd_table_valid(struct ipa *ipa, const struct ipa_mem *mem, - bool route, bool ipv6, bool hashed); + bool route); + +#ifdef IPA_VALIDATE /** * ipa_cmd_data_valid() - Validate command-realted configuration is valid @@ -82,13 +80,6 @@ bool ipa_cmd_data_valid(struct ipa *ipa); #else /* !IPA_VALIDATE */ -static inline bool ipa_cmd_table_valid(struct ipa *ipa, - const struct ipa_mem *mem, bool route, - bool ipv6, bool hashed) -{ - return true; -} - static inline bool ipa_cmd_data_valid(struct ipa *ipa) { return true; diff --git a/drivers/net/ipa/ipa_table.c b/drivers/net/ipa/ipa_table.c index c617a9156f26d..4f5b6749f6aae 100644 --- a/drivers/net/ipa/ipa_table.c +++ b/drivers/net/ipa/ipa_table.c @@ -161,7 +161,7 @@ ipa_table_valid_one(struct ipa *ipa, enum ipa_mem_id mem_id, bool route) else size = (1 + IPA_FILTER_COUNT_MAX) * sizeof(__le64); - if (!ipa_cmd_table_valid(ipa, mem, route, ipv6, hashed)) + if (!ipa_cmd_table_valid(ipa, mem, route)) return false; /* mem->size >= size is sufficient, but we'll demand more */ From patchwork Mon Jul 26 17:40:08 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Elder X-Patchwork-Id: 485853 Delivered-To: patch@linaro.org Received: by 2002:a02:c94a:0:0:0:0:0 with SMTP id u10csp4042300jao; Mon, 26 Jul 2021 10:40:24 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwQDqkeaO6cR8/JeAY8x9jdNXDzF3fF2uosGVXVoD42ANd/R950T11s4azSu2Uq1N9fw09k X-Received: by 2002:a17:906:22db:: with SMTP id q27mr3747420eja.185.1627321224418; Mon, 26 Jul 2021 10:40:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1627321224; cv=none; d=google.com; s=arc-20160816; b=PVnqO2CxKopyKIZ2eUahDMfHOWHB5C1961xo7KOMUGPYJNCxOndeoRjGV4OiJ2Tc/z d3nIPsb3ShsyPWsCU+cq7ehc0okW/lFYZ/3sKCzoN8v3zZwnDvyD1pnsTQvrIHUNz62B 6kVY6eVZjxxzRKQhxgA6oAt+kRdF3uy4KN8bxRtxei3N+Mrp67pI75uvu8U8omK6gJni ifqv9ANypCqmnkLmkNUbeCzXQ5rVbtRpenoDbda2XgZDAURsh7LSs/L6klcgxLzITrUX bzC3Bb/FCjdHAjc356+tAm2cQgLxUhX4X2SdKzfb5BYNMqh2bj4iiBhCz2MNInrRpxNU 52cw== 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=RhapsKA6J25kD25lmyi6/Yv9x0InAtnL2pbV2Xb9qwU=; b=fH/B8BXL54FMms8uq/Cn7V2YKykTAJEjntNi/+YIF/05BqAJEY+iNh6PKMASbHQ03d zPJxZ7aDD145QRtiCmRui67FO/y0XNHfplLFwWx/1krqj0PCgGKUZs9AHuyfsqcme/mc 7E5x5vRfyLtxsb9n5Ade8KdKAdn6RyMh60VBJ6Q4lMuGvaSlu7VFpuA5J1ZEXz45mqhD j8NI6aUs+ywImsvIziI1/+huU9XONY74SMCtb87nvZ+KvUh1uFuLzBJsXLcExCU+qZsQ B/TKYuOwW1+8K27rE1rDQ/E/VNSS5VmE1z1SkTgmn5+e3zgFniAjdwZMz1wgMbEOp742 jS+w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=EgeRPtba; 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 gv3si514404ejc.42.2021.07.26.10.40.24; Mon, 26 Jul 2021 10:40:24 -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=EgeRPtba; 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 S229646AbhGZQ7y (ORCPT + 8 others); Mon, 26 Jul 2021 12:59:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45366 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229851AbhGZQ7r (ORCPT ); Mon, 26 Jul 2021 12:59:47 -0400 Received: from mail-io1-xd29.google.com (mail-io1-xd29.google.com [IPv6:2607:f8b0:4864:20::d29]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0081CC061764 for ; Mon, 26 Jul 2021 10:40:15 -0700 (PDT) Received: by mail-io1-xd29.google.com with SMTP id m13so12860448iol.7 for ; Mon, 26 Jul 2021 10:40:15 -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=RhapsKA6J25kD25lmyi6/Yv9x0InAtnL2pbV2Xb9qwU=; b=EgeRPtba7JmXRFpCb8FHFkqy26AmvA+X5gH4ja6s47tmBi07ies/bKg+QIpedEfGnt mVWdIky5xLde1ZvHr6eg6JlgIUDcmAJ0upfIAo6kaz42joyY8cRNU5xzx9ZSzr/yq5ef AK4muCJVTIpkbnpDark9BNW398xyLVilfvTETNoiJmfbEWtgYvI6gWf0cu8dPYO4uGfx mZPgq8UVbTcEK65nrbN/+AECMrmvC3MczDPGy/tnUqFM2ROaf57QpJtJ70uuxYncRxh2 3OSiENmJjmcxu7i9J4GcMk52Wn+Bk3Ib310OzcH/ZbamQtRd8n5wFE8sDPl/+rRryRQu VxlA== 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=RhapsKA6J25kD25lmyi6/Yv9x0InAtnL2pbV2Xb9qwU=; b=ndYb21oQ2hVR8c7rQ1d4/7VgOgR3wRZfJW0lv2zpoGyKdT+SrlhaBjdLd07GWsMpo2 q378iEiR8spG3NG2mCdv7TGS0c7HkZOt9FOlF/9DEOjX6k8DtiSCyF89bP2/zT2bHPVs RY8rAfbufmvH7gPkRa4aeX2b5Zwl6OaQRmVSoco/xv+vCPuYzukd9OxVMhb8JCw5lymn U6Q+WpBpULztE9fA8aGnjBRna49d+uhG5s+z0Al3tkikquiX11CeA7HJjt6a8JE2tkiQ R2Db91d+cg4+YwKffZgDBrchrR91Ad7j0IRGrwEVa4bkhRf+67K3twoahh7JnOPmzHTs sNaA== X-Gm-Message-State: AOAM532UmxWQAoJws6JsEupPa7tRRc0p6K6patGHMVqAxlcm/8eE+daC Yr176XTLJRr3Nn4fXn7tKf1hDQ== X-Received: by 2002:a02:93a7:: with SMTP id z36mr17237528jah.112.1627321215463; Mon, 26 Jul 2021 10:40:15 -0700 (PDT) Received: from presto.localdomain (c-73-185-129-58.hsd1.mn.comcast.net. [73.185.129.58]) by smtp.gmail.com with ESMTPSA id l4sm202721ilh.41.2021.07.26.10.40.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Jul 2021 10:40:15 -0700 (PDT) From: Alex Elder To: davem@davemloft.net, kuba@kernel.org Cc: leon@kernel.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 Subject: [PATCH net-next 2/4] net: ipa: always validate filter and route tables Date: Mon, 26 Jul 2021 12:40:08 -0500 Message-Id: <20210726174010.396765-3-elder@linaro.org> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20210726174010.396765-1-elder@linaro.org> References: <20210726174010.396765-1-elder@linaro.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org All checks in ipa_table_validate_build() are computed at build time, so build that unconditionally. In ipa_table_valid() calls to ipa_table_valid_one() are missing the IPA pointer parameter is missing in (a bug that shows up only when IPA_VALIDATE is defined). Don't bother checking whether hashed table memory regions are valid if hashed tables are not supported. With those things fixed, have these table validation functions built unconditionally (not dependent on IPA_VALIDATE). Signed-off-by: Alex Elder --- drivers/net/ipa/ipa_table.c | 36 +++++++++++++++++------------------- drivers/net/ipa/ipa_table.h | 16 ---------------- 2 files changed, 17 insertions(+), 35 deletions(-) -- 2.27.0 diff --git a/drivers/net/ipa/ipa_table.c b/drivers/net/ipa/ipa_table.c index 4f5b6749f6aae..c607ebec74567 100644 --- a/drivers/net/ipa/ipa_table.c +++ b/drivers/net/ipa/ipa_table.c @@ -120,8 +120,6 @@ */ #define IPA_ZERO_RULE_SIZE (2 * sizeof(__le32)) -#ifdef IPA_VALIDATE - /* Check things that can be validated at build time. */ static void ipa_table_validate_build(void) { @@ -169,7 +167,7 @@ ipa_table_valid_one(struct ipa *ipa, enum ipa_mem_id mem_id, bool route) return true; /* Hashed table regions can be zero size if hashing is not supported */ - if (hashed && !mem->size) + if (ipa_table_hash_support(ipa) && !mem->size) return true; dev_err(dev, "%s table region %u size 0x%02x, expected 0x%02x\n", @@ -183,14 +181,22 @@ bool ipa_table_valid(struct ipa *ipa) { bool valid; - valid = ipa_table_valid_one(IPA_MEM_V4_FILTER, false); - valid = valid && ipa_table_valid_one(IPA_MEM_V4_FILTER_HASHED, false); - valid = valid && ipa_table_valid_one(IPA_MEM_V6_FILTER, false); - valid = valid && ipa_table_valid_one(IPA_MEM_V6_FILTER_HASHED, false); - valid = valid && ipa_table_valid_one(IPA_MEM_V4_ROUTE, true); - valid = valid && ipa_table_valid_one(IPA_MEM_V4_ROUTE_HASHED, true); - valid = valid && ipa_table_valid_one(IPA_MEM_V6_ROUTE, true); - valid = valid && ipa_table_valid_one(IPA_MEM_V6_ROUTE_HASHED, true); + valid = ipa_table_valid_one(ipa, IPA_MEM_V4_FILTER, false); + valid = valid && ipa_table_valid_one(ipa, IPA_MEM_V6_FILTER, false); + valid = valid && ipa_table_valid_one(ipa, IPA_MEM_V4_ROUTE, true); + valid = valid && ipa_table_valid_one(ipa, IPA_MEM_V6_ROUTE, true); + + if (!ipa_table_hash_support(ipa)) + return valid; + + valid = valid && ipa_table_valid_one(ipa, IPA_MEM_V4_FILTER_HASHED, + false); + valid = valid && ipa_table_valid_one(ipa, IPA_MEM_V6_FILTER_HASHED, + false); + valid = valid && ipa_table_valid_one(ipa, IPA_MEM_V4_ROUTE_HASHED, + true); + valid = valid && ipa_table_valid_one(ipa, IPA_MEM_V6_ROUTE_HASHED, + true); return valid; } @@ -217,14 +223,6 @@ bool ipa_filter_map_valid(struct ipa *ipa, u32 filter_map) return true; } -#else /* !IPA_VALIDATE */ -static void ipa_table_validate_build(void) - -{ -} - -#endif /* !IPA_VALIDATE */ - /* Zero entry count means no table, so just return a 0 address */ static dma_addr_t ipa_table_addr(struct ipa *ipa, bool filter_mask, u16 count) { diff --git a/drivers/net/ipa/ipa_table.h b/drivers/net/ipa/ipa_table.h index 1e2be9fce2f81..b6a9a0d79d68e 100644 --- a/drivers/net/ipa/ipa_table.h +++ b/drivers/net/ipa/ipa_table.h @@ -16,8 +16,6 @@ struct ipa; /* The maximum number of route table entries (IPv4, IPv6; hashed or not) */ #define IPA_ROUTE_COUNT_MAX 15 -#ifdef IPA_VALIDATE - /** * ipa_table_valid() - Validate route and filter table memory regions * @ipa: IPA pointer @@ -35,20 +33,6 @@ bool ipa_table_valid(struct ipa *ipa); */ bool ipa_filter_map_valid(struct ipa *ipa, u32 filter_mask); -#else /* !IPA_VALIDATE */ - -static inline bool ipa_table_valid(struct ipa *ipa) -{ - return true; -} - -static inline bool ipa_filter_map_valid(struct ipa *ipa, u32 filter_mask) -{ - return true; -} - -#endif /* !IPA_VALIDATE */ - /** * ipa_table_hash_support() - Return true if hashed tables are supported * @ipa: IPA pointer From patchwork Mon Jul 26 17:40:09 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Elder X-Patchwork-Id: 485855 Delivered-To: patch@linaro.org Received: by 2002:a02:c94a:0:0:0:0:0 with SMTP id u10csp4042443jao; Mon, 26 Jul 2021 10:40:36 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyNJhqtZTxAlTCPPwAvI2buuyGsjifD+cksx2eGyINp30DwIw4hczZ/yNQYsV+vl3UiOByx X-Received: by 2002:a17:906:31cb:: with SMTP id f11mr18415860ejf.379.1627321235841; Mon, 26 Jul 2021 10:40:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1627321235; cv=none; d=google.com; s=arc-20160816; b=cWkm9ccQyjfecxugCLRYDwnx3eMWJ18FX/aOSotUp0eJUHIKQK0upiYkR4J8ULYd68 y3qXm5lkzqhcfF6+ygNUCAgPbfQRlvTPlgf+aJjH517I8gEUzyb0OTO450hHXhrKqAAc JBd0flomFt6geEVKsS4dhiK4QRqkw8wfdEvFpG2pL2rcI2ldD+4e2HNxksD0jFEsR/XK zb6Frn4pKNL7OYBxcSuJ+yNqid8Jf5fp6LmeH7WKuIlkAfYUd1qJPPFJyLxva/0l2iSe IE3o2UBDu0FQEjtsc8L6NxFi21ksEFbuuW3G1rYJ3XcMfOnkcda+89wV04mQ++c8tIhL A6wQ== 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=igk/eHhWUPu9afoObyctlRd1/zpW6sRE3pcaziGyfBE=; b=Axiy9Hrf1TzZVEq+ZMIdS6lhHNENFfeFP6K19x5wbWl0BHKsplWy+zI7yzyWr+CuF2 xPeV7BH/gwGCtLr7Np7GbJMqNzVhX7wLZJ+TgUbhMhI+LpEQFx7lF/uyFoCmMUdpXK2+ jaxnH3nrc54sZuZfjbh5RRuNF/5ud8fQ9ZkfwHtSySLBPpD7j3/3FixUuVb2IzVASD5t qkFmznd0pmO8eq9QJ0OpIvl8oonCgW6Ooo9O10Uun/O3EXa4bsrOFzowPxd597xLwwDD EOhGxcqgZdbMfrRH5LDg85y6H2GDATsra/0lZDQkg+y9dE/Tzx/DxGkSyH1lxIHq6yvH VDvw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=SXEYKbo2; 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 o16si534687ejh.496.2021.07.26.10.40.35; Mon, 26 Jul 2021 10:40:35 -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=SXEYKbo2; 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 S232041AbhGZRAB (ORCPT + 8 others); Mon, 26 Jul 2021 13:00:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45378 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231694AbhGZQ7t (ORCPT ); Mon, 26 Jul 2021 12:59:49 -0400 Received: from mail-il1-x12c.google.com (mail-il1-x12c.google.com [IPv6:2607:f8b0:4864:20::12c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CEAB3C0613D3 for ; Mon, 26 Jul 2021 10:40:16 -0700 (PDT) Received: by mail-il1-x12c.google.com with SMTP id l11so9751315iln.4 for ; Mon, 26 Jul 2021 10:40:16 -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=igk/eHhWUPu9afoObyctlRd1/zpW6sRE3pcaziGyfBE=; b=SXEYKbo2WkONf7MIIa6qH5ZvPXdhBAWA2/mKCH/HBoyc9OoapZk4hDdOvNmXSh5crZ UkgzMAKZOQOqzxd1si3opZW91wJ+NvZ9AZtaW7ynQH57CC8JL8Bibt7Ps9MeN2NCsQVP aPBRun/tCJf8/2VqBF3PM4hc1ZUeXiSE/lzzwu5Xpp9/mX8qyhiboVihM/R/BYKV/By7 5PDe6OQAvxWtsGaaPC/DASkAoSwO0f5nH7Dc3MJvLQrb+lc7gL8rkA5fPFuRUazSpcpZ Vs6K7saq/eC5i5BYC8biezs1HpueLDurDkPHxCGjXl8/cYgaKazOeQw/bCrWe835fssp 04Gw== 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=igk/eHhWUPu9afoObyctlRd1/zpW6sRE3pcaziGyfBE=; b=aZrqEb8qITsvhGXdDJbSp7oIOURPLn3xnJ1dG7r9Cj5uOxYGcFYVHEOqmxeqFXRPXm O0r127+AayMRfXiLuxjD+FgrQF1VT0TvkCJUMmzy5fSH95maxIYASir2VnCFwReYW8wm XHnz1LhnJGLoiNOrUGuPh/d+tVvY8Lxi8eJvwSdp4A1N+q/UEX5EuJ8yYyD1QYxSnIJk NcIfD79AjYjfNkbVu6MPBBl7oFiOfpYlmFb3XYpYsnCXNbPw06sob9ChOL6wMhH986+N DVLSqlIDYWdB/pgddPtyC9yS3IXwGa6V97bLd9yFrkgKlWgd95uLIC39QbHNhu+/nFpa wK8A== X-Gm-Message-State: AOAM533WYC+6/b4GcjppAwL3VdnS9MBJ4Tdw3/iyEOZQi4FUh8J1vDOQ 1TrRRiGt6g4SgipixOCXkBaAfA== X-Received: by 2002:a05:6e02:13e2:: with SMTP id w2mr13952711ilj.308.1627321216302; Mon, 26 Jul 2021 10:40:16 -0700 (PDT) Received: from presto.localdomain (c-73-185-129-58.hsd1.mn.comcast.net. [73.185.129.58]) by smtp.gmail.com with ESMTPSA id l4sm202721ilh.41.2021.07.26.10.40.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Jul 2021 10:40:16 -0700 (PDT) From: Alex Elder To: davem@davemloft.net, kuba@kernel.org Cc: leon@kernel.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 Subject: [PATCH net-next 3/4] net: ipa: kill the remaining conditional validation code Date: Mon, 26 Jul 2021 12:40:09 -0500 Message-Id: <20210726174010.396765-4-elder@linaro.org> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20210726174010.396765-1-elder@linaro.org> References: <20210726174010.396765-1-elder@linaro.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org There are only a few remaining spots that validate IPA code conditional on whether a symbol is defined at compile time. The checks are not expensive, so just build them always. This completes the removal of all CONFIG_VALIDATE/CONFIG_VALIDATION IPA code. Signed-off-by: Alex Elder --- drivers/net/ipa/Makefile | 3 --- drivers/net/ipa/gsi.c | 2 -- drivers/net/ipa/gsi_trans.c | 4 ---- drivers/net/ipa/ipa_cmd.c | 3 --- drivers/net/ipa/ipa_cmd.h | 11 ----------- drivers/net/ipa/ipa_main.c | 2 -- drivers/net/ipa/ipa_resource.c | 3 +-- 7 files changed, 1 insertion(+), 27 deletions(-) -- 2.27.0 diff --git a/drivers/net/ipa/Makefile b/drivers/net/ipa/Makefile index 506f8d5cd4eeb..75435d40b9200 100644 --- a/drivers/net/ipa/Makefile +++ b/drivers/net/ipa/Makefile @@ -1,6 +1,3 @@ -# Un-comment the next line if you want to validate configuration data -#ccflags-y += -DIPA_VALIDATE - obj-$(CONFIG_QCOM_IPA) += ipa.o ipa-y := ipa_main.o ipa_clock.o ipa_reg.o ipa_mem.o \ diff --git a/drivers/net/ipa/gsi.c b/drivers/net/ipa/gsi.c index 427c68b2ad8f3..3de67ba066a68 100644 --- a/drivers/net/ipa/gsi.c +++ b/drivers/net/ipa/gsi.c @@ -1964,7 +1964,6 @@ static void gsi_evt_ring_init(struct gsi *gsi) static bool gsi_channel_data_valid(struct gsi *gsi, const struct ipa_gsi_endpoint_data *data) { -#ifdef IPA_VALIDATION u32 channel_id = data->channel_id; struct device *dev = gsi->dev; @@ -2010,7 +2009,6 @@ static bool gsi_channel_data_valid(struct gsi *gsi, channel_id, data->channel.event_count); return false; } -#endif /* IPA_VALIDATION */ return true; } diff --git a/drivers/net/ipa/gsi_trans.c b/drivers/net/ipa/gsi_trans.c index 8c795a6a85986..6127370facee5 100644 --- a/drivers/net/ipa/gsi_trans.c +++ b/drivers/net/ipa/gsi_trans.c @@ -90,14 +90,12 @@ int gsi_trans_pool_init(struct gsi_trans_pool *pool, size_t size, u32 count, { void *virt; -#ifdef IPA_VALIDATE if (!size) return -EINVAL; if (count < max_alloc) return -EINVAL; if (!max_alloc) return -EINVAL; -#endif /* IPA_VALIDATE */ /* By allocating a few extra entries in our pool (one less * than the maximum number that will be requested in a @@ -140,14 +138,12 @@ int gsi_trans_pool_init_dma(struct device *dev, struct gsi_trans_pool *pool, dma_addr_t addr; void *virt; -#ifdef IPA_VALIDATE if (!size) return -EINVAL; if (count < max_alloc) return -EINVAL; if (!max_alloc) return -EINVAL; -#endif /* IPA_VALIDATE */ /* Don't let allocations cross a power-of-two boundary */ size = __roundup_pow_of_two(size); diff --git a/drivers/net/ipa/ipa_cmd.c b/drivers/net/ipa/ipa_cmd.c index bda8677eae88d..8900f91509fee 100644 --- a/drivers/net/ipa/ipa_cmd.c +++ b/drivers/net/ipa/ipa_cmd.c @@ -207,8 +207,6 @@ bool ipa_cmd_table_valid(struct ipa *ipa, const struct ipa_mem *mem, bool route) return true; } -#ifdef IPA_VALIDATE - /* Validate the memory region that holds headers */ static bool ipa_cmd_header_valid(struct ipa *ipa) { @@ -343,7 +341,6 @@ bool ipa_cmd_data_valid(struct ipa *ipa) return true; } -#endif /* IPA_VALIDATE */ int ipa_cmd_pool_init(struct gsi_channel *channel, u32 tre_max) { diff --git a/drivers/net/ipa/ipa_cmd.h b/drivers/net/ipa/ipa_cmd.h index ea723419c826b..69cd085d427db 100644 --- a/drivers/net/ipa/ipa_cmd.h +++ b/drivers/net/ipa/ipa_cmd.h @@ -68,8 +68,6 @@ struct ipa_cmd_info { bool ipa_cmd_table_valid(struct ipa *ipa, const struct ipa_mem *mem, bool route); -#ifdef IPA_VALIDATE - /** * ipa_cmd_data_valid() - Validate command-realted configuration is valid * @ipa: - IPA pointer @@ -78,15 +76,6 @@ bool ipa_cmd_table_valid(struct ipa *ipa, const struct ipa_mem *mem, */ bool ipa_cmd_data_valid(struct ipa *ipa); -#else /* !IPA_VALIDATE */ - -static inline bool ipa_cmd_data_valid(struct ipa *ipa) -{ - return true; -} - -#endif /* !IPA_VALIDATE */ - /** * ipa_cmd_pool_init() - initialize command channel pools * @channel: AP->IPA command TX GSI channel pointer diff --git a/drivers/net/ipa/ipa_main.c b/drivers/net/ipa/ipa_main.c index 9810c61a03202..ff5f3fab640d6 100644 --- a/drivers/net/ipa/ipa_main.c +++ b/drivers/net/ipa/ipa_main.c @@ -612,7 +612,6 @@ MODULE_DEVICE_TABLE(of, ipa_match); * */ static void ipa_validate_build(void) { -#ifdef IPA_VALIDATE /* At one time we assumed a 64-bit build, allowing some do_div() * calls to be replaced by simple division or modulo operations. * We currently only perform divide and modulo operations on u32, @@ -646,7 +645,6 @@ static void ipa_validate_build(void) BUILD_BUG_ON(!ipa_aggr_granularity_val(IPA_AGGR_GRANULARITY)); BUILD_BUG_ON(ipa_aggr_granularity_val(IPA_AGGR_GRANULARITY) > field_max(AGGR_GRANULARITY_FMASK)); -#endif /* IPA_VALIDATE */ } static bool ipa_version_valid(enum ipa_version version) diff --git a/drivers/net/ipa/ipa_resource.c b/drivers/net/ipa/ipa_resource.c index 3b2dc216d3a68..e3da95d694099 100644 --- a/drivers/net/ipa/ipa_resource.c +++ b/drivers/net/ipa/ipa_resource.c @@ -29,7 +29,6 @@ static bool ipa_resource_limits_valid(struct ipa *ipa, const struct ipa_resource_data *data) { -#ifdef IPA_VALIDATION u32 group_count; u32 i; u32 j; @@ -65,7 +64,7 @@ static bool ipa_resource_limits_valid(struct ipa *ipa, if (resource->limits[j].min || resource->limits[j].max) return false; } -#endif /* !IPA_VALIDATION */ + return true; } From patchwork Mon Jul 26 17:40:10 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Elder X-Patchwork-Id: 485854 Delivered-To: patch@linaro.org Received: by 2002:a02:c94a:0:0:0:0:0 with SMTP id u10csp4042319jao; Mon, 26 Jul 2021 10:40:26 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxTOM0TPOC9ShWcCN45GIpmTn83zJFJgMC0ObFqEzTh2kzSc6khXRrh0xACWM3QFQOXgLFK X-Received: by 2002:a05:6402:1546:: with SMTP id p6mr22855835edx.206.1627321225936; Mon, 26 Jul 2021 10:40:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1627321225; cv=none; d=google.com; s=arc-20160816; b=TDKksUMevO4Ck9+7ToSI4g0Ws9tVA18sIGRKiIJNz4ClA4Q1B33ykw18A4UnaCbRkv EJo4Fw4jmQ0sSxCT6rWHhjOu0AEjT5SiAsJ14OtAtQzx7NZVdinlYUYadkgN+C82rKtD vfsxRMsJqmlUxdB/SweryZZNfSUhdvdlJRVTfr0QZdrjitZrTG2gwdRH4TPsrjMa6+/q urOkBFyQ6bBkR2/bqxXaPDp4/npsKE5tttNQjg8EGCkJLPnOp8lhWpxuoC6LcY7a7Te9 WZI96xoceVGQEaakzTulH54+x2hGr0eauqeWFOccA29FgRxXck//LktLgYtsL6n2Cqnl YolA== 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=rMhwXuvkKbeYnU6oDXYaGN+W0CVUDzl5mE/XU+7HM3k=; b=Uu8in5EYe1B/JjUixpuYjBJKExpMm6h+j4jquYFk+iwPjTlKTbNvTD68arZLGjrEWw c+Hdg7xCaV4BDzyPUbI+cd78pDuOJwmH8ptlU8Yr2RJVlUzDWjDjitT9Jf7hNtP8p7C6 i4GN18mBBEcT9v42FKVIWqV9cEaSH+QRBPDvG2eG5epSKhLeJHfdiYfoCgn5mkjDiGXH kzeDRtS2dfejMWE3zMrO4pFukM5hmOkb2NxHcwA5A2DPqHOSWzr34+vhZX+jxYTxwg6Q 4CD9cwdzqy1hp3++sSXpSWgHkcyBfvOHAsxh8jcnri+hzovC7NY4JGEphpaInL+Mc0Q+ yd3w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=LH3WAvZF; 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 gv3si514404ejc.42.2021.07.26.10.40.25; Mon, 26 Jul 2021 10:40:25 -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=LH3WAvZF; 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 S231921AbhGZQ74 (ORCPT + 8 others); Mon, 26 Jul 2021 12:59:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45364 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231728AbhGZQ7t (ORCPT ); Mon, 26 Jul 2021 12:59:49 -0400 Received: from mail-io1-xd2e.google.com (mail-io1-xd2e.google.com [IPv6:2607:f8b0:4864:20::d2e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BF059C061757 for ; Mon, 26 Jul 2021 10:40:17 -0700 (PDT) Received: by mail-io1-xd2e.google.com with SMTP id j21so12898159ioo.6 for ; Mon, 26 Jul 2021 10:40:17 -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=rMhwXuvkKbeYnU6oDXYaGN+W0CVUDzl5mE/XU+7HM3k=; b=LH3WAvZFozHwksBA62OcjqWgC5JXBSCJSVYZDvmUSZG3RT7WIMg14xGurLLDuwjmdA JtlkmhkCCrK4KBBrQ/QTuO3i0SHfWKIJ/RC1CoNtu5vaaOGfI+DpKqnZm8a8JFWcdb3A tlM/Co6WUg0vCzmDlS7RbDJ7MrlGQOC7H8CmTNdMK1SZwIKZHII9Nynqv3MdVhAvhaGH csXKc2BdS3++Vsc/aIdk01ZZk/odBkVkbuOWCC+IlzhBkANr2jabUqBLp6AIueDnVsPC uJ9ZkRiXiLJn4LKHyVFsfq2WxwjpblvBJVyivN5uh+/8TE+V8hkEzmM/C1U4WLND+NlL +vlw== 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=rMhwXuvkKbeYnU6oDXYaGN+W0CVUDzl5mE/XU+7HM3k=; b=lN8xnh7FTJIayf6YAPEgpAuyuqfH4wj64J1iPTUWK45OUYC6ZBVr/4mTo7ipc2YK4d vqyyJKyDO2o2gvGRIeMtnPEOw5PWQ758AVHt9KoFUmX1tZj7mJoYz/Pf9X1YVueCf6Vw wvG1SgnL+znC1NRr81DOvIEqVZXa2cpMIWZ9hj8iP86w1ewg11iJYWstNMMo1nSCKzmJ UmpyihdifIELCkCf6dm+GOSc8adOYuUTc6yejIdwNX5QDcR8ftG5s9gU+I5QfVzk5uXM hPrb2f2RzJJRHUymIS8uJrCwqomMw9BCFvTWPI2YrON71BYzwq7bqhlvUeOj30Bm6xTl JCrw== X-Gm-Message-State: AOAM5300TMO2XK8HKxIYgXZ9al2oAeSyrNDkfUXRigNImejYFKAzuQVj IflFl5bM+UKrv3mKvQLshxwagg== X-Received: by 2002:a02:6d5d:: with SMTP id e29mr17618117jaf.44.1627321217136; Mon, 26 Jul 2021 10:40:17 -0700 (PDT) Received: from presto.localdomain (c-73-185-129-58.hsd1.mn.comcast.net. [73.185.129.58]) by smtp.gmail.com with ESMTPSA id l4sm202721ilh.41.2021.07.26.10.40.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Jul 2021 10:40:16 -0700 (PDT) From: Alex Elder To: davem@davemloft.net, kuba@kernel.org Cc: leon@kernel.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 Subject: [PATCH net-next 4/4] net: ipa: use WARN_ON() rather than assertions Date: Mon, 26 Jul 2021 12:40:10 -0500 Message-Id: <20210726174010.396765-5-elder@linaro.org> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20210726174010.396765-1-elder@linaro.org> References: <20210726174010.396765-1-elder@linaro.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org I've added commented assertions to record certain properties that can be assumed to hold in certain places in the IPA code. Convert these into real WARN_ON() calls so the assertions are actually checked, using the standard WARN_ON() mechanism. Where errors can be returned, return an error if a warning is triggered. Signed-off-by: Alex Elder --- drivers/net/ipa/gsi_trans.c | 30 ++++++++++++++++++------------ drivers/net/ipa/ipa_cmd.c | 14 +++++++------- drivers/net/ipa/ipa_endpoint.c | 26 +++++++++++++++----------- drivers/net/ipa/ipa_interrupt.c | 8 +++++--- drivers/net/ipa/ipa_main.c | 5 +---- drivers/net/ipa/ipa_reg.h | 12 ++++++------ drivers/net/ipa/ipa_table.c | 2 +- 7 files changed, 53 insertions(+), 44 deletions(-) -- 2.27.0 diff --git a/drivers/net/ipa/gsi_trans.c b/drivers/net/ipa/gsi_trans.c index 6127370facee5..1544564bc2835 100644 --- a/drivers/net/ipa/gsi_trans.c +++ b/drivers/net/ipa/gsi_trans.c @@ -184,8 +184,8 @@ static u32 gsi_trans_pool_alloc_common(struct gsi_trans_pool *pool, u32 count) { u32 offset; - /* assert(count > 0); */ - /* assert(count <= pool->max_alloc); */ + WARN_ON(!count); + WARN_ON(count > pool->max_alloc); /* Allocate from beginning if wrap would occur */ if (count > pool->count - pool->free) @@ -221,9 +221,10 @@ void *gsi_trans_pool_next(struct gsi_trans_pool *pool, void *element) { void *end = pool->base + pool->count * pool->size; - /* assert(element >= pool->base); */ - /* assert(element < end); */ - /* assert(pool->max_alloc == 1); */ + WARN_ON(element < pool->base); + WARN_ON(element >= end); + WARN_ON(pool->max_alloc != 1); + element += pool->size; return element < end ? element : pool->base; @@ -328,7 +329,8 @@ struct gsi_trans *gsi_channel_trans_alloc(struct gsi *gsi, u32 channel_id, struct gsi_trans_info *trans_info; struct gsi_trans *trans; - /* assert(tre_count <= gsi_channel_trans_tre_max(gsi, channel_id)); */ + if (WARN_ON(tre_count > gsi_channel_trans_tre_max(gsi, channel_id))) + return NULL; trans_info = &channel->trans_info; @@ -404,7 +406,7 @@ void gsi_trans_cmd_add(struct gsi_trans *trans, void *buf, u32 size, u32 which = trans->used++; struct scatterlist *sg; - /* assert(which < trans->tre_count); */ + WARN_ON(which >= trans->tre_count); /* Commands are quite different from data transfer requests. * Their payloads come from a pool whose memory is allocated @@ -437,8 +439,10 @@ int gsi_trans_page_add(struct gsi_trans *trans, struct page *page, u32 size, struct scatterlist *sg = &trans->sgl[0]; int ret; - /* assert(trans->tre_count == 1); */ - /* assert(!trans->used); */ + if (WARN_ON(trans->tre_count != 1)) + return -EINVAL; + if (WARN_ON(trans->used)) + return -EINVAL; sg_set_page(sg, page, size, offset); ret = dma_map_sg(trans->gsi->dev, sg, 1, trans->direction); @@ -457,8 +461,10 @@ int gsi_trans_skb_add(struct gsi_trans *trans, struct sk_buff *skb) u32 used; int ret; - /* assert(trans->tre_count == 1); */ - /* assert(!trans->used); */ + if (WARN_ON(trans->tre_count != 1)) + return -EINVAL; + if (WARN_ON(trans->used)) + return -EINVAL; /* skb->len will not be 0 (checked early) */ ret = skb_to_sgvec(skb, sg, 0, skb->len); @@ -546,7 +552,7 @@ static void __gsi_trans_commit(struct gsi_trans *trans, bool ring_db) u32 avail; u32 i; - /* assert(trans->used > 0); */ + WARN_ON(!trans->used); /* Consume the entries. If we cross the end of the ring while * filling them we'll switch to the beginning to finish. diff --git a/drivers/net/ipa/ipa_cmd.c b/drivers/net/ipa/ipa_cmd.c index 8900f91509fee..cff51731195aa 100644 --- a/drivers/net/ipa/ipa_cmd.c +++ b/drivers/net/ipa/ipa_cmd.c @@ -165,6 +165,10 @@ static void ipa_cmd_validate_build(void) field_max(IP_FLTRT_FLAGS_NHASH_SIZE_FMASK)); BUILD_BUG_ON(field_max(IP_FLTRT_FLAGS_HASH_ADDR_FMASK) != field_max(IP_FLTRT_FLAGS_NHASH_ADDR_FMASK)); + + /* Valid endpoint numbers must fit in the IP packet init command */ + BUILD_BUG_ON(field_max(IPA_PACKET_INIT_DEST_ENDPOINT_FMASK) < + IPA_ENDPOINT_MAX - 1); } /* Validate a memory region holding a table */ @@ -531,9 +535,6 @@ static void ipa_cmd_ip_packet_init_add(struct gsi_trans *trans, u8 endpoint_id) union ipa_cmd_payload *cmd_payload; dma_addr_t payload_addr; - /* assert(endpoint_id < - field_max(IPA_PACKET_INIT_DEST_ENDPOINT_FMASK)); */ - cmd_payload = ipa_cmd_payload_alloc(ipa, &payload_addr); payload = &cmd_payload->ip_packet_init; @@ -557,8 +558,9 @@ void ipa_cmd_dma_shared_mem_add(struct gsi_trans *trans, u32 offset, u16 size, u16 flags; /* size and offset must fit in 16 bit fields */ - /* assert(size > 0 && size <= U16_MAX); */ - /* assert(offset <= U16_MAX && ipa->mem_offset <= U16_MAX - offset); */ + WARN_ON(!size); + WARN_ON(size > U16_MAX); + WARN_ON(offset > U16_MAX || ipa->mem_offset > U16_MAX - offset); offset += ipa->mem_offset; @@ -597,8 +599,6 @@ static void ipa_cmd_ip_tag_status_add(struct gsi_trans *trans) union ipa_cmd_payload *cmd_payload; dma_addr_t payload_addr; - /* assert(tag <= field_max(IP_PACKET_TAG_STATUS_TAG_FMASK)); */ - cmd_payload = ipa_cmd_payload_alloc(ipa, &payload_addr); payload = &cmd_payload->ip_packet_tag_status; diff --git a/drivers/net/ipa/ipa_endpoint.c b/drivers/net/ipa/ipa_endpoint.c index ab02669bae4e6..8070d1a1d5dfd 100644 --- a/drivers/net/ipa/ipa_endpoint.c +++ b/drivers/net/ipa/ipa_endpoint.c @@ -250,17 +250,18 @@ ipa_endpoint_init_ctrl(struct ipa_endpoint *endpoint, bool suspend_delay) /* Suspend is not supported for IPA v4.0+. Delay doesn't work * correctly on IPA v4.2. - * - * if (endpoint->toward_ipa) - * assert(ipa->version != IPA_VERSION_4.2); - * else - * assert(ipa->version < IPA_VERSION_4_0); */ + if (endpoint->toward_ipa) + WARN_ON(ipa->version == IPA_VERSION_4_2); + else + WARN_ON(ipa->version >= IPA_VERSION_4_0); + mask = endpoint->toward_ipa ? ENDP_DELAY_FMASK : ENDP_SUSPEND_FMASK; val = ioread32(ipa->reg_virt + offset); - /* Don't bother if it's already in the requested state */ state = !!(val & mask); + + /* Don't bother if it's already in the requested state */ if (suspend_delay != state) { val ^= mask; iowrite32(val, ipa->reg_virt + offset); @@ -273,7 +274,7 @@ ipa_endpoint_init_ctrl(struct ipa_endpoint *endpoint, bool suspend_delay) static void ipa_endpoint_program_delay(struct ipa_endpoint *endpoint, bool enable) { - /* assert(endpoint->toward_ipa); */ + WARN_ON(!endpoint->toward_ipa); /* Delay mode doesn't work properly for IPA v4.2 */ if (endpoint->ipa->version != IPA_VERSION_4_2) @@ -287,7 +288,8 @@ static bool ipa_endpoint_aggr_active(struct ipa_endpoint *endpoint) u32 offset; u32 val; - /* assert(mask & ipa->available); */ + WARN_ON(!(mask & ipa->available)); + offset = ipa_reg_state_aggr_active_offset(ipa->version); val = ioread32(ipa->reg_virt + offset); @@ -299,7 +301,8 @@ static void ipa_endpoint_force_close(struct ipa_endpoint *endpoint) u32 mask = BIT(endpoint->endpoint_id); struct ipa *ipa = endpoint->ipa; - /* assert(mask & ipa->available); */ + WARN_ON(!(mask & ipa->available)); + iowrite32(mask, ipa->reg_virt + IPA_REG_AGGR_FORCE_CLOSE_OFFSET); } @@ -338,7 +341,7 @@ ipa_endpoint_program_suspend(struct ipa_endpoint *endpoint, bool enable) if (endpoint->ipa->version >= IPA_VERSION_4_0) return enable; /* For IPA v4.0+, no change made */ - /* assert(!endpoint->toward_ipa); */ + WARN_ON(endpoint->toward_ipa); suspended = ipa_endpoint_init_ctrl(endpoint, enable); @@ -1156,7 +1159,8 @@ static bool ipa_endpoint_skb_build(struct ipa_endpoint *endpoint, if (!endpoint->netdev) return false; - /* assert(len <= SKB_WITH_OVERHEAD(IPA_RX_BUFFER_SIZE-NET_SKB_PAD)); */ + WARN_ON(len > SKB_WITH_OVERHEAD(IPA_RX_BUFFER_SIZE - NET_SKB_PAD)); + skb = build_skb(page_address(page), IPA_RX_BUFFER_SIZE); if (skb) { /* Reserve the headroom and account for the data */ diff --git a/drivers/net/ipa/ipa_interrupt.c b/drivers/net/ipa/ipa_interrupt.c index c46df0b7c4e50..e792bc3be5766 100644 --- a/drivers/net/ipa/ipa_interrupt.c +++ b/drivers/net/ipa/ipa_interrupt.c @@ -146,7 +146,7 @@ static void ipa_interrupt_suspend_control(struct ipa_interrupt *interrupt, u32 offset; u32 val; - /* assert(mask & ipa->available); */ + WARN_ON(!(mask & ipa->available)); /* IPA version 3.0 does not support TX_SUSPEND interrupt control */ if (ipa->version == IPA_VERSION_3_0) @@ -206,7 +206,8 @@ void ipa_interrupt_add(struct ipa_interrupt *interrupt, struct ipa *ipa = interrupt->ipa; u32 offset; - /* assert(ipa_irq < IPA_IRQ_COUNT); */ + WARN_ON(ipa_irq >= IPA_IRQ_COUNT); + interrupt->handler[ipa_irq] = handler; /* Update the IPA interrupt mask to enable it */ @@ -222,7 +223,8 @@ ipa_interrupt_remove(struct ipa_interrupt *interrupt, enum ipa_irq_id ipa_irq) struct ipa *ipa = interrupt->ipa; u32 offset; - /* assert(ipa_irq < IPA_IRQ_COUNT); */ + WARN_ON(ipa_irq >= IPA_IRQ_COUNT); + /* Update the IPA interrupt mask to disable it */ interrupt->enabled &= ~BIT(ipa_irq); offset = ipa_reg_irq_en_offset(ipa->version); diff --git a/drivers/net/ipa/ipa_main.c b/drivers/net/ipa/ipa_main.c index ff5f3fab640d6..0567d726c5608 100644 --- a/drivers/net/ipa/ipa_main.c +++ b/drivers/net/ipa/ipa_main.c @@ -253,9 +253,6 @@ ipa_hardware_config_qsb(struct ipa *ipa, const struct ipa_data *data) const struct ipa_qsb_data *data1; u32 val; - /* assert(data->qsb_count > 0); */ - /* assert(data->qsb_count < 3); */ - /* QMB 0 represents DDR; QMB 1 (if present) represents PCIe */ data0 = &data->qsb_data[IPA_QSB_MASTER_DDR]; if (data->qsb_count > 1) @@ -293,7 +290,7 @@ ipa_hardware_config_qsb(struct ipa *ipa, const struct ipa_data *data) */ static u32 ipa_aggr_granularity_val(u32 usec) { - /* assert(usec != 0); */ + WARN_ON(!usec); return DIV_ROUND_CLOSEST(usec * TIMER_FREQUENCY, USEC_PER_SEC) - 1; } diff --git a/drivers/net/ipa/ipa_reg.h b/drivers/net/ipa/ipa_reg.h index b89dec5865a5b..a5b355384d4ae 100644 --- a/drivers/net/ipa/ipa_reg.h +++ b/drivers/net/ipa/ipa_reg.h @@ -99,7 +99,7 @@ struct ipa; static inline u32 arbitration_lock_disable_encoded(enum ipa_version version, u32 mask) { - /* assert(version >= IPA_VERSION_4_0); */ + WARN_ON(version < IPA_VERSION_4_0); if (version < IPA_VERSION_4_9) return u32_encode_bits(mask, GENMASK(20, 17)); @@ -116,7 +116,7 @@ static inline u32 full_flush_rsc_closure_en_encoded(enum ipa_version version, { u32 val = enable ? 1 : 0; - /* assert(version >= IPA_VERSION_4_5); */ + WARN_ON(version < IPA_VERSION_4_5); if (version == IPA_VERSION_4_5 || version == IPA_VERSION_4_7) return u32_encode_bits(val, GENMASK(21, 21)); @@ -409,7 +409,7 @@ static inline u32 ipa_header_size_encoded(enum ipa_version version, val = u32_encode_bits(size, HDR_LEN_FMASK); if (version < IPA_VERSION_4_5) { - /* ipa_assert(header_size == size); */ + WARN_ON(header_size != size); return val; } @@ -429,7 +429,7 @@ static inline u32 ipa_metadata_offset_encoded(enum ipa_version version, val = u32_encode_bits(off, HDR_OFST_METADATA_FMASK); if (version < IPA_VERSION_4_5) { - /* ipa_assert(offset == off); */ + WARN_ON(offset != off); return val; } @@ -812,7 +812,7 @@ ipa_reg_irq_suspend_info_offset(enum ipa_version version) static inline u32 ipa_reg_irq_suspend_en_ee_n_offset(enum ipa_version version, u32 ee) { - /* assert(version != IPA_VERSION_3_0); */ + WARN_ON(version == IPA_VERSION_3_0); if (version < IPA_VERSION_4_9) return 0x00003034 + 0x1000 * ee; @@ -830,7 +830,7 @@ ipa_reg_irq_suspend_en_offset(enum ipa_version version) static inline u32 ipa_reg_irq_suspend_clr_ee_n_offset(enum ipa_version version, u32 ee) { - /* assert(version != IPA_VERSION_3_0); */ + WARN_ON(version == IPA_VERSION_3_0); if (version < IPA_VERSION_4_9) return 0x00003038 + 0x1000 * ee; diff --git a/drivers/net/ipa/ipa_table.c b/drivers/net/ipa/ipa_table.c index c607ebec74567..2324e1b93e37d 100644 --- a/drivers/net/ipa/ipa_table.c +++ b/drivers/net/ipa/ipa_table.c @@ -231,7 +231,7 @@ static dma_addr_t ipa_table_addr(struct ipa *ipa, bool filter_mask, u16 count) if (!count) return 0; -/* assert(count <= max_t(u32, IPA_FILTER_COUNT_MAX, IPA_ROUTE_COUNT_MAX)); */ + WARN_ON(count > max_t(u32, IPA_FILTER_COUNT_MAX, IPA_ROUTE_COUNT_MAX)); /* Skip over the zero rule and possibly the filter mask */ skip = filter_mask ? 1 : 2;