Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp2722202iob; Fri, 6 May 2022 09:02:57 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxcXX66Zr/KpXc61vOE3CmduBf4SdMG+I/u0ftkHtyyiuZACJQBtYcwS0wUG+KKE1OcqX4u X-Received: by 2002:a17:902:db05:b0:15e:89c9:e805 with SMTP id m5-20020a170902db0500b0015e89c9e805mr4239922plx.107.1651852976740; Fri, 06 May 2022 09:02:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1651852976; cv=none; d=google.com; s=arc-20160816; b=wwIru8a9muUWGVLh+3HAgvBTQS52rBVhk45wO0RWZsYCUUVRVyTFaq820ttkrn0ZX/ BNCvguqXG8UIf5jL8h0lERXfBiGZurNsQX08YyYaV1S47FTZNv/sSzjd8OoTbr/b5rJy m7glyxgXqv1r12LDGhLuY2WOYpnJ8VHknXkbTDI6tNc+k/IHQxPkzW/Zc2BFrBiLBY85 PcmaTuBFPQiO0k97Cg3rg3bazzv2MwNjTc9iE8qVwU6p5OEfdrXO9wdbeQ7MRyN4XFYE LbpGMQ1s6OwtCzwkEMhu2QsgFXKQfMmjH6OAeqVRavjnyfZQLqYokt1E+b6TsoBTcc+z 7+uw== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=QWFIL9Fnm/y+TXMB4x1CM4h2/LXIIsW+MSoDhW1+TYA=; b=Is2Bmq+rSKzr4GRfgePmLq90WDbTC5vxMYhNxa3ZqXE/kXAx4jV6SW5+xXHblYSPpL hSw69oUF7r3SD2QkA2poGkc86Pj4ITGujQMl957SwStwTaR6mDLpUe/S47gK28xJ2cLK TK9kNqCupeBY+Eg2AvkYsd/o56g5vGBsZYpCnzmi++TejGJRAZ/l2UbaVZA7tsYa3yCo GFtAVeZX8BeucAjRoutbrgJLGsGipbE5I4+B+RpA61nT66IwbNm/n9dVaJ2bsYdR7j1X 0BC37BSJKANwvvIqeADfMEC9ZLRtFVSYBQZpTUxiSW3U65jf2QXLXzfkyapvdbQ9ECjG 00yA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="ea/IEDDL"; 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=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id c10-20020a63724a000000b003ab158e5a5esi4755550pgn.121.2022.05.06.09.02.33; Fri, 06 May 2022 09:02:56 -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=@linuxfoundation.org header.s=korg header.b="ea/IEDDL"; 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=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1358320AbiEDRlU (ORCPT + 99 others); Wed, 4 May 2022 13:41:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39176 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1356657AbiEDRJh (ORCPT ); Wed, 4 May 2022 13:09:37 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9F5C247056; Wed, 4 May 2022 09:55:19 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 4F476B827A1; Wed, 4 May 2022 16:55:18 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 08916C385AA; Wed, 4 May 2022 16:55:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1651683317; bh=KrCa3xx+pLiibOz+R1GUnejvUmDg0sP1/REd83K1u+4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ea/IEDDLnleWBcQzu9ml3Zk+S1mQ1rwb5PbEqwv5q852/Z8dWkbZMnHsqisJNYOJu 1xFQyEJhwQRV9bzGwQdelSvwA+gQcGYLrkRh5y3AoSJKUZusCyP0O+UB1SEMYr9u2p ymQ0F/t8idLtsEFy48UOlDfybzjUj8HFgPLilRxE= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, stable , Christophe Leroy Subject: [PATCH 5.15 174/177] eeprom: at25: Use DMA safe buffers Date: Wed, 4 May 2022 18:46:07 +0200 Message-Id: <20220504153109.261304023@linuxfoundation.org> X-Mailer: git-send-email 2.36.0 In-Reply-To: <20220504153053.873100034@linuxfoundation.org> References: <20220504153053.873100034@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.7 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, 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 From: Christophe Leroy commit 5b47b751b760ee1c74a51660fd096aa148a362cd upstream. Reading EEPROM fails with following warning: [ 16.357496] ------------[ cut here ]------------ [ 16.357529] fsl_spi b01004c0.spi: rejecting DMA map of vmalloc memory [ 16.357698] WARNING: CPU: 0 PID: 371 at include/linux/dma-mapping.h:326 fsl_spi_cpm_bufs+0x2a0/0x2d8 [ 16.357775] CPU: 0 PID: 371 Comm: od Not tainted 5.16.11-s3k-dev-01743-g19beecbfe9d6-dirty #109 [ 16.357806] NIP: c03fbc9c LR: c03fbc9c CTR: 00000000 [ 16.357825] REGS: e68d9b20 TRAP: 0700 Not tainted (5.16.11-s3k-dev-01743-g19beecbfe9d6-dirty) [ 16.357849] MSR: 00029032 CR: 24002282 XER: 00000000 [ 16.357931] [ 16.357931] GPR00: c03fbc9c e68d9be0 c26d06a0 00000039 00000001 c0d36364 c0e96428 00000027 [ 16.357931] GPR08: 00000001 00000000 00000023 3fffc000 24002282 100d3dd6 100a2ffc 00000000 [ 16.357931] GPR16: 100cd280 100b0000 00000000 aff54f7e 100d0000 100d0000 00000001 100cf328 [ 16.357931] GPR24: 100cf328 00000000 00000003 e68d9e30 c156b410 e67ab4c0 e68d9d38 c24ab278 [ 16.358253] NIP [c03fbc9c] fsl_spi_cpm_bufs+0x2a0/0x2d8 [ 16.358292] LR [c03fbc9c] fsl_spi_cpm_bufs+0x2a0/0x2d8 [ 16.358325] Call Trace: [ 16.358336] [e68d9be0] [c03fbc9c] fsl_spi_cpm_bufs+0x2a0/0x2d8 (unreliable) [ 16.358388] [e68d9c00] [c03fcb44] fsl_spi_bufs.isra.0+0x94/0x1a0 [ 16.358436] [e68d9c20] [c03fd970] fsl_spi_do_one_msg+0x254/0x3dc [ 16.358483] [e68d9cb0] [c03f7e50] __spi_pump_messages+0x274/0x8a4 [ 16.358529] [e68d9ce0] [c03f9d30] __spi_sync+0x344/0x378 [ 16.358573] [e68d9d20] [c03fb52c] spi_sync+0x34/0x60 [ 16.358616] [e68d9d30] [c03b4dec] at25_ee_read+0x138/0x1a8 [ 16.358667] [e68d9e50] [c04a8fb8] bin_attr_nvmem_read+0x98/0x110 [ 16.358725] [e68d9e60] [c0204b14] kernfs_fop_read_iter+0xc0/0x1fc [ 16.358774] [e68d9e80] [c0168660] vfs_read+0x284/0x410 [ 16.358821] [e68d9f00] [c016925c] ksys_read+0x6c/0x11c [ 16.358863] [e68d9f30] [c00160e0] ret_from_syscall+0x0/0x28 ... [ 16.359608] ---[ end trace a4ce3e34afef0cb5 ]--- [ 16.359638] fsl_spi b01004c0.spi: unable to map tx dma This is due to the AT25 driver using buffers on stack, which is not possible with CONFIG_VMAP_STACK. As mentionned in kernel Documentation (Documentation/spi/spi-summary.rst): - Follow standard kernel rules, and provide DMA-safe buffers in your messages. That way controller drivers using DMA aren't forced to make extra copies unless the hardware requires it (e.g. working around hardware errata that force the use of bounce buffering). Modify the driver to use a buffer located in the at25 device structure which is allocated via kmalloc during probe. Protect writes in this new buffer with the driver's mutex. Fixes: b587b13a4f67 ("[PATCH] SPI eeprom driver") Cc: stable Signed-off-by: Christophe Leroy Link: https://lore.kernel.org/r/230a9486fc68ea0182df46255e42a51099403642.1648032613.git.christophe.leroy@csgroup.eu Signed-off-by: Greg Kroah-Hartman --- drivers/misc/eeprom/at25.c | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) --- a/drivers/misc/eeprom/at25.c +++ b/drivers/misc/eeprom/at25.c @@ -30,6 +30,8 @@ */ #define FM25_SN_LEN 8 /* serial number length */ +#define EE_MAXADDRLEN 3 /* 24 bit addresses, up to 2 MBytes */ + struct at25_data { struct spi_device *spi; struct mutex lock; @@ -38,6 +40,7 @@ struct at25_data { struct nvmem_config nvmem_config; struct nvmem_device *nvmem; u8 sernum[FM25_SN_LEN]; + u8 command[EE_MAXADDRLEN + 1]; }; #define AT25_WREN 0x06 /* latch the write enable */ @@ -60,8 +63,6 @@ struct at25_data { #define FM25_ID_LEN 9 /* ID length */ -#define EE_MAXADDRLEN 3 /* 24 bit addresses, up to 2 MBytes */ - /* Specs often allow 5 msec for a page write, sometimes 20 msec; * it's important to recover from write timeouts. */ @@ -76,7 +77,6 @@ static int at25_ee_read(void *priv, unsi { struct at25_data *at25 = priv; char *buf = val; - u8 command[EE_MAXADDRLEN + 1]; u8 *cp; ssize_t status; struct spi_transfer t[2]; @@ -90,12 +90,15 @@ static int at25_ee_read(void *priv, unsi if (unlikely(!count)) return -EINVAL; - cp = command; + cp = at25->command; instr = AT25_READ; if (at25->chip.flags & EE_INSTR_BIT3_IS_ADDR) if (offset >= (1U << (at25->addrlen * 8))) instr |= AT25_INSTR_BIT3; + + mutex_lock(&at25->lock); + *cp++ = instr; /* 8/16/24-bit address is written MSB first */ @@ -114,7 +117,7 @@ static int at25_ee_read(void *priv, unsi spi_message_init(&m); memset(t, 0, sizeof(t)); - t[0].tx_buf = command; + t[0].tx_buf = at25->command; t[0].len = at25->addrlen + 1; spi_message_add_tail(&t[0], &m); @@ -122,8 +125,6 @@ static int at25_ee_read(void *priv, unsi t[1].len = count; spi_message_add_tail(&t[1], &m); - mutex_lock(&at25->lock); - /* Read it all at once. * * REVISIT that's potentially a problem with large chips, if @@ -151,7 +152,7 @@ static int fm25_aux_read(struct at25_dat spi_message_init(&m); memset(t, 0, sizeof(t)); - t[0].tx_buf = &command; + t[0].tx_buf = at25->command; t[0].len = 1; spi_message_add_tail(&t[0], &m); @@ -161,6 +162,8 @@ static int fm25_aux_read(struct at25_dat mutex_lock(&at25->lock); + at25->command[0] = command; + status = spi_sync(at25->spi, &m); dev_dbg(&at25->spi->dev, "read %d aux bytes --> %d\n", len, status);