Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp4630579rwl; Tue, 28 Mar 2023 09:13:03 -0700 (PDT) X-Google-Smtp-Source: AKy350Yq1SnxuaPBGmN4d5V6Nh2YYg0cxJP29HLbenQCC7BW+5kwKfMlv8mAvjpBMNVLEBeReqUu X-Received: by 2002:a17:90a:bc85:b0:23d:816:faa9 with SMTP id x5-20020a17090abc8500b0023d0816faa9mr19037767pjr.12.1680019983115; Tue, 28 Mar 2023 09:13:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680019983; cv=none; d=google.com; s=arc-20160816; b=tXtiw65Gk53qiw2lzJu+EPo+2tCITYHA2wVUFkSLAA+9JjUWLP20y5kz3xzK08l0pc uhNfsM3UXJrJVNnrX61d8S+cwRudMZYLOtWY6/4cmBr6GFL8AneU9YSHVfdnnC+8+vII EHeI6SnwWTajdkLSinHMfsA3ZhqUDgilUJz5kJTDSMk35xJOhEdm0xlzu7I2lWzKLLsT wJwsx+Rn1JR0SdVmPMwNB1b0H7tET5dHDtbOszKtePdghRsLdVS3RfaCgY4+WKV7jYQO V3NmQvICP10fUy33rm1uxMz+6Y7PLx4se84MLWi+bT5TDTLIm6xDCV00+DYcQq5OZOrL pmIQ== 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=ZeYDQrGbPRqt70DYrQNatAGDz+G9B8QI11p/DnsQkr0=; b=GnbrtDzXhjOxhYO8pG9/OekiDdvPYqmHH913LsBYNDx1JdWTEZCxrp4VgDG8P6KGBL Bvl95vJhOacwGJOrhrQJ9L9WcZQjtvkc1UzhvHHk/NnXEqD2DZmnpLHoOGbtpwgN/ZLH TOkz/1uxwKUNxHGG98k57VTKTwBPPjTFwm3Bs8SmVPShJqS6B0OdVgeDJvWqQ+OwPh2h 7l1dbSsRerBTI7uiQ7akAo1LP5diHEFG5mllG41e9PBPOgeCSedDVrYVyzEaoC0/+DL5 oR/q2gB+3HSfm7icWWRDLkpzvyN0NK3s3PA6+6uBcM+UESRSlqU3HRR4WrPk7AFQMWm+ G4tA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=AM3iLxks; 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 n5-20020a17090ac68500b0023eb779a705si8451966pjt.64.2023.03.28.09.12.50; Tue, 28 Mar 2023 09:13:03 -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=AM3iLxks; 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 S233058AbjC1QIt (ORCPT + 99 others); Tue, 28 Mar 2023 12:08:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40664 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232822AbjC1QIl (ORCPT ); Tue, 28 Mar 2023 12:08:41 -0400 Received: from mail-io1-xd2a.google.com (mail-io1-xd2a.google.com [IPv6:2607:f8b0:4864:20::d2a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 40099BDDF for ; Tue, 28 Mar 2023 09:08:39 -0700 (PDT) Received: by mail-io1-xd2a.google.com with SMTP id o12so5570449iow.6 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=ve2n8FxS0w02orCIC8pIAUCGFzipOBE33+/y8fTv97J7GRTGID8DqtTrYB/SvIZ69i QLpZsURAzJukvwmeeu7alorq73hX6hDJvPq5MQfBF7HeXC9NXa2mjzfhekaJSAktjuyz dJuyCWFrG7uoCkI2ASro16gsssWx7oefgy6RzmeeneTxzV7iDUPqPJew+8C2g3xvPzVV oIx4UNB/yhytL60xgzhumrtkAud1qQGF52VVt/2OUp6s4bqCiEjYfHYnlpKRgKglyzTS bALToKpmS0LC5aUR1oxHdGGa+Lua3VeWseId2tVBtlv3A2y5dUH3nqBWaxcAwX7v+fbZ Rx+g== X-Gm-Message-State: AO0yUKWjpsUCZPdpgslrCMfDLeFp5RjFsJDCRLeQMd9JejBys5h2DOHU UsTYeeOlzS40p5nRBwVk389sBg== 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 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") Signed-off-by: Alex Elder --- 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) -- 2.34.1