Received: by 2002:a05:6a10:9afc:0:0:0:0 with SMTP id t28csp1049370pxm; Thu, 3 Mar 2022 09:18:53 -0800 (PST) X-Google-Smtp-Source: ABdhPJyfM/sva+ZnmAYLX7Lvt+U79JcjQzh22L9Msao6fa77lVYtHo+zuMJ6Z9FR6AJbsszEpBWa X-Received: by 2002:a17:902:e5d1:b0:151:99c4:e575 with SMTP id u17-20020a170902e5d100b0015199c4e575mr8399704plf.67.1646327933454; Thu, 03 Mar 2022 09:18:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1646327933; cv=none; d=google.com; s=arc-20160816; b=QrHWr9xllKd+n5/fxo3Hb9agOGhZJiGvItPAvlYJZ/2MwTPS8Zb6uaYUL+2o9CMAl4 ciZf+zYypkxvFEsuoRwEU8AkvxiyX/52W+sEF+bmeToBFufohJR/rXwNzHW713VuQCK0 jhokQDLyjwhZD/0pnqsKxEy/iXbySrW2u3YKKXc7ibfmzK+te+lile1AyrH9CoaDkwfQ pF1wLJV96fSfr8sCJzcQSKRVOMC+JFeTSyLixO7niumIXMcacKMK3jenCVubMwzLprIh wsIlmL22hnQ2AB8RLCKtYzjVs/8JYusf1+jLwGmgNlFL05DGkfnl9rFtBk1oxVSvUQ2+ i9oQ== 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=PFcCtGt63rBp0kucxIHsntg/HdnJkcA4oD5l63d9a3E=; b=U35Hs5htZTKQkmR9ckALIDYfVLKx97UjgZYm7Jtrms5hvQ7t8YdKF+OSUqcbKhu4JH Bte7OUW6QwlJQ7Bp+5TQbcK/pE1GkGae2txTSW2SUsCg0EeztXermaMXOLwcxZucBglZ Q6yhtLWB35qs/lntO4j4HXqAWj3NlhMnfJiFZLwzJFUwJkfmEu46DBOpO6K3vdxzxBgV 9W7JfqP128Hlp+9mxwLC68Ns/PrDDWCqFyXEctvDJllM3sds2GpcNYCbu/W8V0+N4km0 y/yB4+ToKLml6vS9CN2TPTMQbbZbh7+weEiv2dbUu3Ig9nINgBtL8DyBkwGVUJq7VNgN 8+Qg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@walle.cc header.s=mail2016061301 header.b=JbU6lT9g; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id q35-20020a635063000000b003796ec07919si2755812pgl.300.2022.03.03.09.18.36; Thu, 03 Mar 2022 09:18:53 -0800 (PST) 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=@walle.cc header.s=mail2016061301 header.b=JbU6lT9g; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234926AbiCCQSe (ORCPT + 99 others); Thu, 3 Mar 2022 11:18:34 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34218 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233778AbiCCQSX (ORCPT ); Thu, 3 Mar 2022 11:18:23 -0500 X-Greylist: delayed 150116 seconds by postgrey-1.37 at lindbergh.monkeyblade.net; Thu, 03 Mar 2022 08:17:37 PST Received: from ssl.serverraum.org (ssl.serverraum.org [176.9.125.105]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 510222409B; Thu, 3 Mar 2022 08:17:31 -0800 (PST) Received: from mwalle01.kontron.local. (unknown [213.135.10.150]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-384) server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by ssl.serverraum.org (Postfix) with ESMTPSA id 49F902223B; Thu, 3 Mar 2022 17:17:29 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=walle.cc; s=mail2016061301; t=1646324250; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=PFcCtGt63rBp0kucxIHsntg/HdnJkcA4oD5l63d9a3E=; b=JbU6lT9gA0vzBY0dz3e94kJ/OGyeZJZSJbYWL+9fPmX7eKB6GJwz6P+MsJyn2SN0XoS1vF hr9Jc10NWzX5jilTfcOPebKpTC9S9c47WGfEPHwdX5E+uvK6La+F+gZp2x7b7mgH2aBxBX 95jxKtw4oDFeZ1hQ1aEF6AlUXePndvw= From: Michael Walle To: Codrin Ciubotariu , Nicolas Ferre , Alexandre Belloni , Claudiu Beznea , Sumit Semwal , =?UTF-8?q?Christian=20K=C3=B6nig?= Cc: linux-i2c@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-media@vger.kernel.org, dri-devel@lists.freedesktop.org, linaro-mm-sig@lists.linaro.org, Michael Walle , stable@vger.kernel.org Subject: [PATCH] i2c: at91: use dma safe buffers Date: Thu, 3 Mar 2022 17:17:24 +0100 Message-Id: <20220303161724.3324948-1-michael@walle.cc> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham 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 The supplied buffer might be on the stack and we get the following error message: [ 3.312058] at91_i2c e0070600.i2c: rejecting DMA map of vmalloc memory Use i2c_{get,put}_dma_safe_msg_buf() to get a DMA-able memory region if necessary. Cc: stable@vger.kernel.org Signed-off-by: Michael Walle --- I'm not sure if or which Fixes: tag I should add to this patch. The issue seems to be since a very long time, but nobody seem to have triggered it. FWIW, I'm using the sff,sfp driver, which triggers this. drivers/i2c/busses/i2c-at91-master.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/drivers/i2c/busses/i2c-at91-master.c b/drivers/i2c/busses/i2c-at91-master.c index b0eae94909f4..a7a22fedbaba 100644 --- a/drivers/i2c/busses/i2c-at91-master.c +++ b/drivers/i2c/busses/i2c-at91-master.c @@ -656,6 +656,7 @@ static int at91_twi_xfer(struct i2c_adapter *adap, struct i2c_msg *msg, int num) unsigned int_addr_flag = 0; struct i2c_msg *m_start = msg; bool is_read; + u8 *dma_buf; dev_dbg(&adap->dev, "at91_xfer: processing %d messages:\n", num); @@ -703,7 +704,18 @@ static int at91_twi_xfer(struct i2c_adapter *adap, struct i2c_msg *msg, int num) dev->msg = m_start; dev->recv_len_abort = false; + if (dev->use_dma) { + dma_buf = i2c_get_dma_safe_msg_buf(m_start, 1); + if (!dma_buf) { + ret = -ENOMEM; + goto out; + } + dev->buf = dma_buf; + } + + ret = at91_do_twi_transfer(dev); + i2c_put_dma_safe_msg_buf(dma_buf, m_start, !ret); ret = (ret < 0) ? ret : num; out: -- 2.30.2