From patchwork Thu Oct 27 12:26:29 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Elder X-Patchwork-Id: 11764 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp200474wru; Thu, 27 Oct 2022 05:29:01 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6NSkidsq7srMK4FfEb4VelJviQCcy0WGm2GZxpPJHJsVVIWsMfFRXn+mKIUCeSoF3pW1Xh X-Received: by 2002:a17:907:97d5:b0:7ac:5f72:6c1a with SMTP id js21-20020a17090797d500b007ac5f726c1amr12227693ejc.126.1666873741335; Thu, 27 Oct 2022 05:29:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666873741; cv=none; d=google.com; s=arc-20160816; b=GWBOViOEhVWSneukf1Kfw4Vp1WrUY4e4/oTti9wjxBZxYAL0+IihK+GoboXYseX/YD 1Mnba8Pf2dOmy4hj+2oVFnIz1Hbjv1iokuxfqR7raluAOv9sv6ryjHBtqIDDiwq1vuK/ zdtDo3GxhwDzjRSlg3Fo8KAkfv7brfRGwMm5Hx+U3QM/F/NSizQoTWb6CupbsAu0i+eS qthFXzzr59uUBh2J0mRetwaMo6S93hreGDLadoLZgA17UHZ6dZobCm77QVhNJ+N/84aI jdOrAMYNZtHgGYP+e7tjJZSDR4Fv/1sWNxrHlRzij1NBTkOckpkzc2ZKd6aowTm5altC sQfg== 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=PANmuigY2dyK4ROc5rs4Gly3suQYhUI4Jvo2R9OvA2c=; b=GtI7gIYN0a0Vs+wb3WbyXemrJqsJNdAFpOrXXYqIFJQBKW1mmb1kHzrQyHKROgEwsn smgfrukKsf/QcsuK2DAtewzYgWVfoiNQb5jXatTdppe7zqErkQu9+pw+0AOGFbsbl008 6KEfIqJyNAjHCDxiU3B7YjKxatzh41zyIs7ONzJNA+cgJ+MYmhKc7pdCY0FaP+4L2zwp CABrjU0TrZl0NiADQ5iKKHlrtaDaOjnrAMfVXqj07AVwx2DXrZn7brJ+5Y2nV6Ze0UGq BEoNxOSOdPaLT4Nd152QeDOKy6PjwoP6NSw9cBcLNb6NP7oV7wYryT+cWCPE18ofxo5N NN0w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=CNIPTfja; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id he41-20020a1709073da900b007815e9c5b80si1540898ejc.617.2022.10.27.05.28.35; Thu, 27 Oct 2022 05:29:01 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=CNIPTfja; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 S235606AbiJ0M1A (ORCPT + 99 others); Thu, 27 Oct 2022 08:27:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39008 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235557AbiJ0M0n (ORCPT ); Thu, 27 Oct 2022 08:26:43 -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 D43D9134AB3 for ; Thu, 27 Oct 2022 05:26:42 -0700 (PDT) Received: by mail-io1-xd29.google.com with SMTP id y143so461056iof.9 for ; Thu, 27 Oct 2022 05:26:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=PANmuigY2dyK4ROc5rs4Gly3suQYhUI4Jvo2R9OvA2c=; b=CNIPTfja4d7m0UUvAc898mJLSi8nuvTEtwk390CUT8LLOZ1Yvw6rMwssAbUQFEmB83 AAw/OYfkSg+b5It3jiavbaVjKPJ0VxHdydf4Hhueu2M7P+4oLvjAhR4ulNs4E5JQZNmO uTAtYpTZPKgwt4wJDjtzIAWZSaBYSTmslPpv47BzwfOekUMR5BhdZUj6C4sTCqkv/c1v gN6Qc9qFT0qpNKM5yEgRvsZrTXd729hp6tYoReRAuibU+gujlXUbdWW9IKJpvzvoYb+L fQy1m6utqPHp+d/BceLWEMvQzR6AphefF06vF4AoXgzIpg4+mckq3xlpgN7de5E8680J FGlg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=PANmuigY2dyK4ROc5rs4Gly3suQYhUI4Jvo2R9OvA2c=; b=q8hwSKSVjNdPhDZY/6rm4U7HnySzYo1JAzBXJ3u/TKvOTyMVGJ62LyRkNVL+kU4n+P bVsHhT/Qpm2SS5jAwx1gqZ65BJmgYEadcF75yk2612TAw1OZhzFPaBdPrzhSMe2NMvmx b/oukfD9whSUtj3FBvnEEen6azI8YJGBmWF5jXqRRPCU3U8GGWWxipiGkhEz3AbYhd8M 6uVSJI72101qaAN4Y2AnqNt33IIBtG1TxAElKAO++BZJeFfmF3qrxMrvmN9CazT/J1Zs ByAHXc5Po9/sFyj/WKWA/bQ64IjqpmNZNgQDKgTK4ddjrYNvLjXpX+8lm9YUw7tOgRFc PpSA== X-Gm-Message-State: ACrzQf0QV2/ISNSPl4JCxC/4koRMKrWQhnoQrE629mdH2XQWZLrz5xYU PZxYM9KYp4nCC/iuriMsZDyePg== X-Received: by 2002:a02:c90a:0:b0:363:2b87:887c with SMTP id t10-20020a02c90a000000b003632b87887cmr31914891jao.72.1666873602491; Thu, 27 Oct 2022 05:26:42 -0700 (PDT) Received: from localhost.localdomain ([98.61.227.136]) by smtp.gmail.com with ESMTPSA id w24-20020a05663800d800b003566ff0eb13sm526528jao.34.2022.10.27.05.26.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Oct 2022 05:26:41 -0700 (PDT) From: Alex Elder To: davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com Cc: mka@chromium.org, evgreen@chromium.org, andersson@kernel.org, quic_cpratapa@quicinc.com, quic_avuyyuru@quicinc.com, quic_jponduru@quicinc.com, quic_subashab@quicinc.com, elder@kernel.org, netdev@vger.kernel.org, linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH net-next 4/7] net: ipa: more completely check endpoint validity Date: Thu, 27 Oct 2022 07:26:29 -0500 Message-Id: <20221027122632.488694-5-elder@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221027122632.488694-1-elder@linaro.org> References: <20221027122632.488694-1-elder@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1747843800427144254?= X-GMAIL-MSGID: =?utf-8?q?1747843800427144254?= Ensure all defined TX endpoints are in the range [0, CONS_PIPES) and defined RX endpoints are within [PROD_LOWEST, PROD_LOWEST+PROD_PIPES). Modify the way local variables are used to make the checks easier to understand. Check for each endpoint being in valid range in the loop, and drop the logical-AND check of initialized against unavailable IDs. Signed-off-by: Alex Elder --- drivers/net/ipa/ipa_endpoint.c | 67 +++++++++++++++++++--------------- 1 file changed, 37 insertions(+), 30 deletions(-) diff --git a/drivers/net/ipa/ipa_endpoint.c b/drivers/net/ipa/ipa_endpoint.c index 093e11ec7c2d1..6fc3cc6379fb0 100644 --- a/drivers/net/ipa/ipa_endpoint.c +++ b/drivers/net/ipa/ipa_endpoint.c @@ -1843,14 +1843,13 @@ int ipa_endpoint_config(struct ipa *ipa) struct device *dev = &ipa->pdev->dev; const struct ipa_reg *reg; u32 initialized; + u32 tx_count; + u32 rx_count; u32 rx_base; - u32 rx_mask; - u32 tx_mask; - int ret = 0; - u32 max; + u32 limit; u32 val; - /* Prior to IPAv3.5, the FLAVOR_0 register was not supported. + /* Prior to IPA v3.5, the FLAVOR_0 register was not supported. * Furthermore, the endpoints were not grouped such that TX * endpoint numbers started with 0 and RX endpoints had numbers * higher than all TX endpoints, so we can't do the simple @@ -1866,33 +1865,25 @@ int ipa_endpoint_config(struct ipa *ipa) } /* Find out about the endpoints supplied by the hardware, and ensure - * the highest one doesn't exceed the number we support. + * the highest one doesn't exceed the number supported by software. */ reg = ipa_reg(ipa, FLAVOR_0); val = ioread32(ipa->reg_virt + ipa_reg_offset(reg)); - /* Our RX is an IPA producer */ + /* Our RX is an IPA producer; our TX is an IPA consumer. */ + tx_count = ipa_reg_decode(reg, MAX_CONS_PIPES, val); + rx_count = ipa_reg_decode(reg, MAX_PROD_PIPES, val); rx_base = ipa_reg_decode(reg, PROD_LOWEST, val); - max = rx_base + ipa_reg_decode(reg, MAX_PROD_PIPES, val); - if (max > IPA_ENDPOINT_MAX) { - dev_err(dev, "too many endpoints (%u > %u)\n", - max, IPA_ENDPOINT_MAX); + + limit = rx_base + rx_count; + if (limit > IPA_ENDPOINT_MAX) { + dev_err(dev, "too many endpoints, %u > %u\n", + limit, IPA_ENDPOINT_MAX); return -EINVAL; } - rx_mask = GENMASK(max - 1, rx_base); - /* Our TX is an IPA consumer */ - max = ipa_reg_decode(reg, MAX_CONS_PIPES, val); - tx_mask = GENMASK(max - 1, 0); - - ipa->available = rx_mask | tx_mask; - - /* Check for initialized endpoints not supported by the hardware */ - if (ipa->initialized & ~ipa->available) { - dev_err(dev, "unavailable endpoint id(s) 0x%08x\n", - ipa->initialized & ~ipa->available); - ret = -EINVAL; /* Report other errors too */ - } + /* Mark all supported RX and TX endpoints as available */ + ipa->available = GENMASK(limit - 1, rx_base) | GENMASK(tx_count - 1, 0); initialized = ipa->initialized; while (initialized) { @@ -1901,16 +1892,32 @@ int ipa_endpoint_config(struct ipa *ipa) initialized ^= BIT(endpoint_id); - /* Make sure it's pointing in the right direction */ - endpoint = &ipa->endpoint[endpoint_id]; - if ((endpoint_id < rx_base) != endpoint->toward_ipa) { - dev_err(dev, "endpoint id %u wrong direction\n", + if (endpoint_id >= limit) { + dev_err(dev, "invalid endpoint id, %u > %u\n", + endpoint_id, limit - 1); + return -EINVAL; + } + + if (!(BIT(endpoint_id) & ipa->available)) { + dev_err(dev, "unavailable endpoint id %u\n", endpoint_id); - ret = -EINVAL; + return -EINVAL; } + + /* Make sure it's pointing in the right direction */ + endpoint = &ipa->endpoint[endpoint_id]; + if (endpoint->toward_ipa) { + if (endpoint_id < tx_count) + continue; + } else if (endpoint_id >= rx_base) { + continue; + } + + dev_err(dev, "endpoint id %u wrong direction\n", endpoint_id); + return -EINVAL; } - return ret; + return 0; } void ipa_endpoint_deconfig(struct ipa *ipa)