From patchwork Tue Mar 28 16:08:33 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Elder X-Patchwork-Id: 668222 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 103B4C6FD18 for ; Tue, 28 Mar 2023 16:08:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232883AbjC1QIt (ORCPT ); Tue, 28 Mar 2023 12:08:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40506 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232877AbjC1QIm (ORCPT ); Tue, 28 Mar 2023 12:08:42 -0400 Received: from mail-io1-xd33.google.com (mail-io1-xd33.google.com [IPv6:2607:f8b0:4864:20::d33]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 40454DBE2 for ; Tue, 28 Mar 2023 09:08:39 -0700 (PDT) Received: by mail-io1-xd33.google.com with SMTP id q6so5580996iot.2 for ; Tue, 28 Mar 2023 09:08:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1680019718; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=ZeYDQrGbPRqt70DYrQNatAGDz+G9B8QI11p/DnsQkr0=; b=AM3iLxks4PZF2oOZ8SG+noafJkJHYtZKMOP8cbso20aH5Hax3P8HbwYP32gWXHyB0x MTGDNV5lpCFBdrFoEof7cxqC9WytuGTQUvKsAvpYqoTsPaTdE3oWpIMjp/5EZRdPFiU1 WZXBN1F8F71BwnI8FGXxra8ArbQPXdG9lLOEFAYJBaG+TKgDp+oMdtnaUEjbTbfKrj1J s4c94fjGXcNYyhwFpWgcGEraIcgiL+SsxDZSLTTlfLu/GAgfLTYxtStl7ZKJsAqLLIsi kmTwX3UYgGJVPrkEiz8f1i+MxGlgEsq1QronfYqtlESJQ4wX1f2dO8lYpvrQdjcZ1dXJ 7EmQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680019718; 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=ZeYDQrGbPRqt70DYrQNatAGDz+G9B8QI11p/DnsQkr0=; b=EQ5O08BNWQA5ItRjfNK1Y+9rNSkaDB1Gs3KfnKs2cwxPCO2x2ITE0M5mMPrPY8DLwa kEILZ950rn1RUuYeGnYU5sPsowFVJcwVyDLWSGNEB+O098gKwYAVb8FmjCA3Qi/V8HGK YLrCU037RjFuzaO6FSIsEM+KGLS3rhh1XWWYL/OXQ6dqPzU65F08QFqfDQnagQLPDfL/ DmnrMjrb/Q4K5cen5TX6ltpD3TknlUPMbz+FjfrYHG4ifQpuCRElSecrP6q7Ngn/KZYC crkgaPAYUYoYuHGybBfhpM1QgZDsA7uO32r9qU457Bd8QqOwavGOgm6WRHvqDsD6oqcp CRvA== X-Gm-Message-State: AO0yUKXfCfLaYUpchQoaOByd/DK5HDWwvfEZosMK+3JiBSWqtKSgmaKt /tCgzw7sexkAtsUMk8cKajHViQ== X-Google-Smtp-Source: AK7set9NnweZPwKGZ6Qvn3oSo/IYtPZC5W8x3ZJAzYNTMogy6llDtemEQaN3sv8W4f+JSdL/5cHAog== X-Received: by 2002:a5e:9901:0:b0:752:6338:3d8 with SMTP id t1-20020a5e9901000000b00752633803d8mr12636325ioj.6.1680019718488; Tue, 28 Mar 2023 09:08:38 -0700 (PDT) Received: from localhost.localdomain ([98.61.227.136]) by smtp.gmail.com with ESMTPSA id g8-20020a5edf48000000b00758917bc309sm4956724ioq.31.2023.03.28.09.08.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Mar 2023 09:08:37 -0700 (PDT) From: Alex Elder To: davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com Cc: quic_bjorande@quicinc.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 v2] net: ipa: compute DMA pool size properly Date: Tue, 28 Mar 2023 11:08:33 -0500 Message-Id: <20230328160833.2861095-1-elder@linaro.org> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@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") Signed-off-by: Alex Elder Reviewed-by: Leon Romanovsky --- Note: This was reported via private communication. 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)