Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp4664846rwl; Tue, 28 Mar 2023 09:36:55 -0700 (PDT) X-Google-Smtp-Source: AKy350apXLPmY9FivF7MvOVVubTcCd84W1/mZ6f2i9IhmsTT2OC82IGeXK2ZvJTBp+zDeABZ7clz X-Received: by 2002:a17:907:c249:b0:932:fc34:88e with SMTP id tj9-20020a170907c24900b00932fc34088emr16968698ejc.52.1680021414761; Tue, 28 Mar 2023 09:36:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680021414; cv=none; d=google.com; s=arc-20160816; b=jFe/ZM5R3+2DXRmLxdowYLn1y6Z+KdJKdcCIwe9B+fOBninIIVA2tHe4uYudmq6skm e1VQVoNBVPSELiHXODqUlO0MC6W1/IQphIQJ6h99hVNPKMapd7CMoXydpW9SgM9nI+sx UOyfDVtpvITkmyWVnqBNEA3IQMUdtrJDP06qEL/FkdCiveTeKa6HpTknh2POBs7fVCk6 7eP9Knb84U0+k7dx4LBqn7Rs4GToVm14k7hPvResWMufJcVhbO1xHi9QyqNrERzcsEfD 9suvZU1VHGYwsMpGyv71uzPr+656R25zi3QZOFJbP9BXNYkovzDeiOuK1yZgGxgBbkXh iSbQ== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=HZlLwQPOb8jKLc2eNXMwjH3kvxbHnpPjAYHKfKgd7uA=; b=UlQyrPHIIlO8fnN7oi/tfREWUGceMsPN25pFE0ihmUB6x+4z+1cRHrEszpptC0D/Qc tGSoLnKu6QACnpuwN8Fz3Ut1eVFQdB5hAqutXLNlqSCmDZMHJx5G94GFpl+O/gCmjzfy 0bgD8ouGYPkweRmCFogwslw17SozNTVsl/TzeF/0GekEf931AxiT3AchRvTu1f+T0fpb acKmYK9AcAMTLCaVhrevB4H3whyoiGEINXEsgAQNOSXFj8n26upJrQUgmebtFuUKR2/l p+2z7DIWLruX6YKW0wJBwJM3PsGZ4QTOl60uIlpYw9hCBQCEL0X7B823fhn7sW1cA+Fd BHmg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Qtxy9wPV; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id gt36-20020a1709072da400b0093defbd6292si13221327ejc.1049.2023.03.28.09.36.29; Tue, 28 Mar 2023 09:36:54 -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=Qtxy9wPV; 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 S232665AbjC1Q17 (ORCPT + 99 others); Tue, 28 Mar 2023 12:27:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37310 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229815AbjC1Q15 (ORCPT ); Tue, 28 Mar 2023 12:27:57 -0400 Received: from mail-il1-x136.google.com (mail-il1-x136.google.com [IPv6:2607:f8b0:4864:20::136]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DAF471716 for ; Tue, 28 Mar 2023 09:27:55 -0700 (PDT) Received: by mail-il1-x136.google.com with SMTP id s1so6606156ild.6 for ; Tue, 28 Mar 2023 09:27:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1680020875; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=HZlLwQPOb8jKLc2eNXMwjH3kvxbHnpPjAYHKfKgd7uA=; b=Qtxy9wPVh5rqdceW19ctke0VfOWZMgcfxj6GjZesd+Pd9vieH4JM1u8sejWiGo2BxB WT2qiUUZE5kv7/kYXwFQwDi4BKmVmod9Z9YoY39MubGBP8Q5PYUKTsm3hNjqW2YUXGYA duSYZBfxSHuODhD80wW3+aRpuL4SPAxpIS14OOgD8i2lX/3R1dLLTMF4Ogyt/Zlo5WUw 5uLA613pQMPoqacuHvClHq8/2Wfmz+k+S/S5W1kNSQ1YwiRA5jb73pXIRyhITApxjZtv jn40+ffjxJd3ZTS9WJ14eeJ9czJLt47Ks33FNntjUbmfUTxzMUYnFV+QJ5qQk+Sfw4XY vJFg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680020875; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=HZlLwQPOb8jKLc2eNXMwjH3kvxbHnpPjAYHKfKgd7uA=; b=JpMoImWbYGM6KrH1MJ6KaHMm8M+tOffVXfgfq9/E5iKubiNMCH+ks/9QAK8PtsN7hS g5iXkOyzot1BhmZt0Bwc3umiKuZ7edsQTi3o4TrGhEjXkPoU/Ub/bUy//u+GoKvpWJIF t1mTPSiEfpntFxoV2Xjd/BF9FkXMuzayUTKAbeY8qsTDqjH8zXuuINH8XQ69ucX4BanO K8p844UCzqjrdtoMrSC4BhzUWgXSaPEd+N97h3RnHHTzW3eugoFyU3ZS6JkutRbgqM4t zMFR6dZ64+Ur98nUtrvRR69Kylv7DVMQt2/qbflPe23MXQSnaPVCJ+MbXM0bBgAfvB24 tcLA== X-Gm-Message-State: AAQBX9fjYDhVzICwwpazr7nEskRg8yDlrxS1lcrmbbQXz9Lurix7UcAC dbdPKEr3vMWj+yNX2p7a9z0Khw== X-Received: by 2002:a92:c8c6:0:b0:315:8bc0:1d85 with SMTP id c6-20020a92c8c6000000b003158bc01d85mr12800420ilq.11.1680020874908; Tue, 28 Mar 2023 09:27:54 -0700 (PDT) Received: from localhost.localdomain ([98.61.227.136]) by smtp.gmail.com with ESMTPSA id g2-20020a92c7c2000000b003159b6d97d6sm8642814ilk.52.2023.03.28.09.27.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Mar 2023 09:27:54 -0700 (PDT) From: Alex Elder To: davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com Cc: quic_bjorande@quicinc.com, mbloch@nvidia.com, caleb.connolly@linaro.org, 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 v3] net: ipa: compute DMA pool size properly Date: Tue, 28 Mar 2023 11:27:51 -0500 Message-Id: <20230328162751.2861791-1-elder@linaro.org> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-0.2 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS autolearn=unavailable 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 In gsi_trans_pool_init_dma(), the total size of a pool of memory used for DMA transactions is calculated. However the calculation is done incorrectly. For 4KB pages, this total size is currently always more than one page, and as a result, the calculation produces a positive (though incorrect) total size. The code still works in this case; we just end up with fewer DMA pool entries than we intended. Bjorn Andersson tested booting a kernel with 16KB pages, and hit a null pointer derereference in sg_alloc_append_table_from_pages(), descending from gsi_trans_pool_init_dma(). The cause of this was that a 16KB total size was going to be allocated, and with 16KB pages the order of that allocation is 0. The total_size calculation yielded 0, which eventually led to the crash. Correcting the total_size calculation fixes the problem. Reported-by: Bjorn Andersson Tested-by: Bjorn Andersson Fixes: 9dd441e4ed57 ("soc: qcom: ipa: GSI transactions") Reviewed-by: Mark Bloch Signed-off-by: Alex Elder --- Note: This was reported via private communication. v3: - Added Mark Bloch's reviewed-by tag. v2: - Added Bjorn's actual name to tags. drivers/net/ipa/gsi_trans.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/net/ipa/gsi_trans.c b/drivers/net/ipa/gsi_trans.c index 0f52c068c46d6..ee6fb00b71eb6 100644 --- a/drivers/net/ipa/gsi_trans.c +++ b/drivers/net/ipa/gsi_trans.c @@ -156,7 +156,7 @@ int gsi_trans_pool_init_dma(struct device *dev, struct gsi_trans_pool *pool, * gsi_trans_pool_exit_dma() can assume the total allocated * size is exactly (count * size). */ - total_size = get_order(total_size) << PAGE_SHIFT; + total_size = PAGE_SIZE << get_order(total_size); virt = dma_alloc_coherent(dev, total_size, &addr, GFP_KERNEL); if (!virt) -- 2.34.1