Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp2475510pxb; Thu, 11 Feb 2021 13:24:12 -0800 (PST) X-Google-Smtp-Source: ABdhPJzDFiCNey2zdV8XjhlyhtHBsD6TIkRCxAaU5AJFIVBZCLi7Zqsz9DLLSzQ2wnvteSDH8O2w X-Received: by 2002:a50:858a:: with SMTP id a10mr117634edh.122.1613078652348; Thu, 11 Feb 2021 13:24:12 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1613078652; cv=none; d=google.com; s=arc-20160816; b=Gb3fSK3nTwfHTx5W2d4QiMOaQboeyhJtOS60AtD7wHz2C0TOBDUN2yp28TNXmeekCx 7U6RJuznNNXZgTys3m1ASi4tBvrIffV/mvkeKgtcvplUkRH2ZhMv/nnRubOaP1MGJRor FyZU5aTJ5A+YjP5q+RmRBK7yVnV222RfRWTO9e3rWUKV9cbpLWUTp9UzoqK0XIZnEJYo 6Hhlh8QDhx4b68N0nIOGcYp1TVwZKX781+jTzqu8z9MG2xgcN4C+VQuC6m682UwMsBjm cMPjw9S4HalMthmcZcOZsirzhmOfJ8+LnR/kT/HA3iFfhjdJmJn9nEFlo0XQGspqfbFa dJcA== 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=8Qrga60o/lyaLM8rZ05SjxSzhBr8SgrRcVc1JO91zNY=; b=HnT07+9UfPjIFz9pGqUMtM9u45p+xqva8dG118F2UPElSMxJg/m+qyx/Bw2q8bGJTS tHEyeJNjHn/MnMwpuBMN8VcHrRde7Jn4TuLU9BU8rhcXu7qo/jHYUhmtgZ3TEEo9NstX 1kLMNM0PquyxL6bjzCRAxRyhsTLvabmiArZho0bpW+MLGqfyTRyG3ac0Q2DGnnefHCmO ap6mfSYCTSwd8KVmO1V1+6C/1xapgnzuvZYX/3a9pTvp7K9sd3LMBpP6FpVigFI5Rt59 gG/U/CRTTlpBG4NF4bY2jCba4isY8YEsHJDg3dCUByD3VNkALfwp1croDY9z1ZdT9Mmx rDAg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=lJxYYFeL; 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 cq14si5325257edb.499.2021.02.11.13.23.48; Thu, 11 Feb 2021 13:24:12 -0800 (PST) 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=lJxYYFeL; 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 S229938AbhBKVVG (ORCPT + 99 others); Thu, 11 Feb 2021 16:21:06 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43668 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229553AbhBKVUx (ORCPT ); Thu, 11 Feb 2021 16:20:53 -0500 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 A6607C06178C for ; Thu, 11 Feb 2021 13:19:34 -0800 (PST) Received: by mail-il1-x129.google.com with SMTP id w1so5239056ilm.12 for ; Thu, 11 Feb 2021 13:19:34 -0800 (PST) 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=8Qrga60o/lyaLM8rZ05SjxSzhBr8SgrRcVc1JO91zNY=; b=lJxYYFeLSvXh8SjWSJ83KiNCbHsmbgYwbUjFxiVKKGQF6Rlo5CNW67Rz6/zxicammH qGn+r9Zrzzfp9lNFWMGnJAZubT8ABGUo9y3qYARNWXfMMhHRHIb35BWs6GcXzwHA3csD 7YcOcpaXDY0iF6bHbdAT1fzR6hyOhfho2k3Lxv7GLERQaIJ3UZDiGU/uGbIjgxI/uOcU +UHKLqEwFE/4Tl/3KhrKln4KvFrQ8HlfqVlYCyEjCz1X179oiZXFatXJFdAqaTXzdsO3 tANwb89LvY3SVIXynhMvxFXt5jwiN8CiMIuL6124HPLD1jnQ+21aw9GJbleHbtY0PAop /OzA== 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=8Qrga60o/lyaLM8rZ05SjxSzhBr8SgrRcVc1JO91zNY=; b=NCQoDenJ0Oe4KNB4qBaXIQcF+oOOXsjZntyfpeaVhvK9xTlW5hK03kVp/Pr+Gk1esl nX5l1Fnfm+b5Q4kt8qEjVINt15LhgXl7e/akSrvqzfYs+0y5Y8Jd5vwYwaxbnuJLA4iI 5/bU3XvrzxIgV/++ufbd8eXrgcv+vJqtNuC1Sk8vAW35UuniMPGDSwiujjDHab0cHaHX GugniWuqCuKtIMMYO3SnHJ8iqlad/iIhJ1FvuDtxVMVH8s/j6miUTL3TAFyotz0rXmRM KNZd1Kk4RXkZlqL/nBKlN9cegO7ZLZnxEtIgUdXwjQ4j33DRcXAZUWeJLRI0KQVKorTM WRvw== X-Gm-Message-State: AOAM532xKIVPK8C7MKRptIEneI0p5hk1HItJYQICOPkWwO6JZbNKCvvK TEE5MF8flsI8bo1ecYUI5fBgGg== X-Received: by 2002:a92:cb52:: with SMTP id f18mr55476ilq.294.1613078374166; Thu, 11 Feb 2021 13:19:34 -0800 (PST) Received: from beast.localdomain (c-73-185-129-58.hsd1.mn.comcast.net. [73.185.129.58]) by smtp.gmail.com with ESMTPSA id j10sm3155718ilc.50.2021.02.11.13.19.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Feb 2021 13:19:33 -0800 (PST) From: Alex Elder To: davem@davemloft.net, kuba@kernel.org Cc: elder@kernel.org, evgreen@chromium.org, bjorn.andersson@linaro.org, cpratapa@codeaurora.org, subashab@codeaurora.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 net-next 3/5] net: ipa: fix register write command validation Date: Thu, 11 Feb 2021 15:19:25 -0600 Message-Id: <20210211211927.28061-4-elder@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20210211211927.28061-1-elder@linaro.org> References: <20210211211927.28061-1-elder@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org In ipa_cmd_register_write_valid() we verify that values we will supply to a REGISTER_WRITE IPA immediate command will fit in the fields that need to hold them. This patch fixes some issues in that function and ipa_cmd_register_write_offset_valid(). The dev_err() call in ipa_cmd_register_write_offset_valid() has some printf format errors: - The name of the register (corresponding to the string format specifier) was not supplied. - The IPA base offset and offset need to be supplied separately to match the other format specifiers. Also make the ~0 constant used there to compute the maximum supported offset value explicitly unsigned. There are two other issues in ipa_cmd_register_write_valid(): - There's no need to check the hash flush register for platforms (like IPA v4.2) that do not support hashed tables - The highest possible endpoint number, whose status register offset is computed, is COUNT - 1, not COUNT. Fix these problems, and add some additional commentary. Signed-off-by: Alex Elder --- drivers/net/ipa/ipa_cmd.c | 32 ++++++++++++++++++++++++-------- 1 file changed, 24 insertions(+), 8 deletions(-) diff --git a/drivers/net/ipa/ipa_cmd.c b/drivers/net/ipa/ipa_cmd.c index 97b50fee60089..fd8bf6468d313 100644 --- a/drivers/net/ipa/ipa_cmd.c +++ b/drivers/net/ipa/ipa_cmd.c @@ -1,7 +1,7 @@ // SPDX-License-Identifier: GPL-2.0 /* Copyright (c) 2012-2018, The Linux Foundation. All rights reserved. - * Copyright (C) 2019-2020 Linaro Ltd. + * Copyright (C) 2019-2021 Linaro Ltd. */ #include @@ -244,11 +244,15 @@ static bool ipa_cmd_register_write_offset_valid(struct ipa *ipa, if (ipa->version != IPA_VERSION_3_5_1) bit_count += hweight32(REGISTER_WRITE_FLAGS_OFFSET_HIGH_FMASK); BUILD_BUG_ON(bit_count > 32); - offset_max = ~0 >> (32 - bit_count); + offset_max = ~0U >> (32 - bit_count); + /* Make sure the offset can be represented by the field(s) + * that holds it. Also make sure the offset is not outside + * the overall IPA memory range. + */ if (offset > offset_max || ipa->mem_offset > offset_max - offset) { dev_err(dev, "%s offset too large 0x%04x + 0x%04x > 0x%04x)\n", - ipa->mem_offset + offset, offset_max); + name, ipa->mem_offset, offset, offset_max); return false; } @@ -261,12 +265,24 @@ static bool ipa_cmd_register_write_valid(struct ipa *ipa) const char *name; u32 offset; - offset = ipa_reg_filt_rout_hash_flush_offset(ipa->version); - name = "filter/route hash flush"; - if (!ipa_cmd_register_write_offset_valid(ipa, name, offset)) - return false; + /* If hashed tables are supported, ensure the hash flush register + * offset will fit in a register write IPA immediate command. + */ + if (ipa->version != IPA_VERSION_4_2) { + offset = ipa_reg_filt_rout_hash_flush_offset(ipa->version); + name = "filter/route hash flush"; + if (!ipa_cmd_register_write_offset_valid(ipa, name, offset)) + return false; + } - offset = IPA_REG_ENDP_STATUS_N_OFFSET(IPA_ENDPOINT_COUNT); + /* Each endpoint can have a status endpoint associated with it, + * and this is recorded in an endpoint register. If the modem + * crashes, we reset the status endpoint for all modem endpoints + * using a register write IPA immediate command. Make sure the + * worst case (highest endpoint number) offset of that endpoint + * fits in the register write command field(s) that must hold it. + */ + offset = IPA_REG_ENDP_STATUS_N_OFFSET(IPA_ENDPOINT_COUNT - 1); name = "maximal endpoint status"; if (!ipa_cmd_register_write_offset_valid(ipa, name, offset)) return false; -- 2.20.1