Message ID | 20230328162751.2861791-1-elder@linaro.org |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp2354049vqo; Tue, 28 Mar 2023 09:37:51 -0700 (PDT) X-Google-Smtp-Source: AKy350Y5A294FZQAhh+U6GhQCnP5KYQeebgC5ywkKMkHyC6zHr8DrFcksHFAJjxvfuBgukzDq5LQ X-Received: by 2002:aa7:db59:0:b0:4fa:7fd8:8f6a with SMTP id n25-20020aa7db59000000b004fa7fd88f6amr14311027edt.38.1680021470916; Tue, 28 Mar 2023 09:37:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680021470; cv=none; d=google.com; s=arc-20160816; b=SFnQGTCYJQyN4kJW5qcJ6G285S7pxpXeap+SltzTHD1IK70XVEoj1ge7O8VhC5+t87 76cBaDvQcHoosEQJhlQIgBXvBsLho8cLUqY31ROa6g0NyxOmAWhEHb7ad7F0LrGL9ysP lCBWPC3jCE9znZo5szMpD+z8nU0EFxhm0VSqHg/SjuelExEijjz2oRSv1t+JlQOhPFLU 6g+VHRbemuJ/ocFMdsNDag/38gOUD0fYT2aiBOGvAJGZakevm8xnTzfRZxTsXjH27Yy+ glIFViZUWNr4/Ob18iD3OFJi4LVUvdg6dY660HygaDzF+NhM0Wn/dMG258E7IU8FZxDf vQ2Q== 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id dy20-20020a05640231f400b004fa760de417si32388791edb.122.2023.03.28.09.37.27; Tue, 28 Mar 2023 09:37:50 -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 S230510AbjC1Q17 (ORCPT <rfc822;rua109.linux@gmail.com> + 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 <rfc822;linux-kernel@vger.kernel.org>); 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 <linux-kernel@vger.kernel.org>; Tue, 28 Mar 2023 09:27:55 -0700 (PDT) Received: by mail-il1-x136.google.com with SMTP id s1so6606156ild.6 for <linux-kernel@vger.kernel.org>; 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 <elder@linaro.org> 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: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1761630053958860367?= X-GMAIL-MSGID: =?utf-8?q?1761630193745409463?= |
Series |
[net,v3] net: ipa: compute DMA pool size properly
|
|
Commit Message
Alex Elder
March 28, 2023, 4:27 p.m. UTC
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 <quic_bjorande@quicinc.com> Tested-by: Bjorn Andersson <quic_bjorande@quicinc.com> Fixes: 9dd441e4ed57 ("soc: qcom: ipa: GSI transactions") Reviewed-by: Mark Bloch <mbloch@nvidia.com> Signed-off-by: Alex Elder <elder@linaro.org> --- 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(-)
Comments
On Tue, Mar 28, 2023 at 11:27:51AM -0500, Alex Elder wrote: > 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 <quic_bjorande@quicinc.com> > Tested-by: Bjorn Andersson <quic_bjorande@quicinc.com> > Fixes: 9dd441e4ed57 ("soc: qcom: ipa: GSI transactions") > Reviewed-by: Mark Bloch <mbloch@nvidia.com> > Signed-off-by: Alex Elder <elder@linaro.org> > --- > 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(-) > Thanks, Reviewed-by: Leon Romanovsky <leonro@nvidia.com>
Hello: This patch was applied to netdev/net.git (main) by Jakub Kicinski <kuba@kernel.org>: On Tue, 28 Mar 2023 11:27:51 -0500 you wrote: > 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. > > [...] Here is the summary with links: - [net,v3] net: ipa: compute DMA pool size properly https://git.kernel.org/netdev/net/c/6c75dc94f2b2 You are awesome, thank you!
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)