From patchwork Thu Mar 23 00:17:59 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 95875 Delivered-To: patch@linaro.org Received: by 10.140.89.233 with SMTP id v96csp497849qgd; Wed, 22 Mar 2017 17:36:30 -0700 (PDT) X-Received: by 10.84.231.130 with SMTP id g2mr12371340plk.96.1490229390109; Wed, 22 Mar 2017 17:36:30 -0700 (PDT) Return-Path: Received: from bombadil.infradead.org (bombadil.infradead.org. [65.50.211.133]) by mx.google.com with ESMTPS id t10si3546622pgc.141.2017.03.22.17.36.29 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 22 Mar 2017 17:36:30 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-mtd-bounces+patch=linaro.org@lists.infradead.org designates 65.50.211.133 as permitted sender) client-ip=65.50.211.133; Authentication-Results: mx.google.com; dkim=pass header.i=@lists.infradead.org; dkim=neutral (body hash did not verify) header.i=@infradead.org; dkim=neutral (body hash did not verify) header.i=@nifty.com; spf=pass (google.com: best guess record for domain of linux-mtd-bounces+patch=linaro.org@lists.infradead.org designates 65.50.211.133 as permitted sender) smtp.mailfrom=linux-mtd-bounces+patch=linaro.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=JVQ2ML0p+K4hq+a5JtRC0RtL/AzVRL5FBlLv7LYDEh4=; b=rMFFqzcn2BMdnnyE1SRra6YT/C 0Uob/PmTv8W5Q2szR/wssq5Amdo0e/iQOPtyjUt9nZUbjUlS5Yot9wz99MNeh36MX7uUFoeYKRHLs fDZggludXkETSoRzd1Nc5pynBRf4AVdHv/BmznMoUW78hUiZIMC5tmKdcHyR0LosDPJQ1Q7R2q9ui 8/qRSRFAWFbU/9HxbVfLqnJAWo4B3Pv3nM74oPECWoOyIVtGcmW8FMz5/dWdz5InGqbmbawMH5zyp jmdzk0wLG9ZQmsCPCAN2WiOTM3qKkcOu34b3zqW4C/4HxibAccldVFFTl/+a0lIk+o/JGljwgS57K c2+HVxMA==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1cqqjl-0007bJ-5c; Thu, 23 Mar 2017 00:36:21 +0000 Received: from casper.infradead.org ([2001:770:15f::2]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1cqqj1-0006Ye-I6 for linux-mtd@bombadil.infradead.org; Thu, 23 Mar 2017 00:35:35 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=References:In-Reply-To:Message-Id:Date: Subject:Cc:To:From:Sender:Reply-To:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=tAWrSgcQVneiGXvOoaLoJAbPxjJj4CZnMRp/9mZnZg0=; b=V/ARqUMBa46FZzmkqTP65bbWZ hejhQBdTEzvxPlf9MQNzZoED5g1TmB6pOSgTSlyUwvlMF6OeP8GMP2Ox6SmFbufE9A001NvEwQslV 6EmPunsRHO75FYufa1noubrHRiEqeumIuyMqbBc8cnaP0o+J6akBVZ42nF+F667JdyKby0gFJzxoZ 1bVURJXHGYHp6NdiegJQNhPtWo+7N49YL0Kb1Xec1aFxUKJy2fipx3YNGTR2C4dJ/jnVUtFqMtGYW xQBdH99cjztILdxIZqmWNiMUG3cLnzHFIAIpTCKa52orTZ7P4oBcanuKtXW6SLNmK1cbhW26pICWg SXtx6c+6Q==; Received: from conuserg-09.nifty.com ([210.131.2.76]) by casper.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1cqqTT-0001GV-AJ for linux-mtd@lists.infradead.org; Thu, 23 Mar 2017 00:19:34 +0000 Received: from grover.sesame (FL1-111-169-71-157.osk.mesh.ad.jp [111.169.71.157]) (authenticated) by conuserg-09.nifty.com with ESMTP id v2N0I4c2008011; Thu, 23 Mar 2017 09:18:33 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-09.nifty.com v2N0I4c2008011 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1490228314; bh=tAWrSgcQVneiGXvOoaLoJAbPxjJj4CZnMRp/9mZnZg0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ljnDPP1chsMyMQefrisne4fHBkbsyiQCedemITqZqyNbnUh0sni7I3oHFYrS6YhUN XIyaATJB3yYfuxQMLo+4m22pR3tYHHj3S57LkaDEYHgORj96W8jd50OLP5Gxv1ibnM RMc7A6ImN+hN8Rtq2eZVc1sc/ReLbpIPjMKq4NZpQdyuHiMv1omN3TbMhLpHeQuzhs tQhzSVHCTHC5W7xmnJCv72w6GEpfwJv8KM/Jh+7nT52rgUvKLg8K3GTNsBkC+4jTIL f8HkFI3Hk7R0RMLIRh1aF8x9lPQxvPr/5RuNMg0M7CiTGcs3ecdKVviULqy2pseKHp XUZocqJ5tauJw== X-Nifty-SrcIP: [111.169.71.157] From: Masahiro Yamada To: linux-mtd@lists.infradead.org Subject: [RESEND PATCH v2 50/53] mtd: nand: allocate aligned buffers if NAND_OWN_BUFFERS is unset Date: Thu, 23 Mar 2017 09:17:59 +0900 Message-Id: <1490228282-10805-24-git-send-email-yamada.masahiro@socionext.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1490228282-10805-1-git-send-email-yamada.masahiro@socionext.com> References: <1490228282-10805-1-git-send-email-yamada.masahiro@socionext.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170323_001931_896694_1F56BE9A X-CRM114-Status: GOOD ( 16.98 ) X-Spam-Score: -1.2 (-) X-Spam-Report: SpamAssassin version 3.4.1 on casper.infradead.org summary: Content analysis details: (-1.2 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- 0.7 SPF_SOFTFAIL SPF: sender does not match SPF record (softfail) -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: laurent.monat@idquantique.com, Boris Brezillon , thorsten.christiansson@idquantique.com, Dinh Nguyen , Enrico Jorns , Artem Bityutskiy , Marek Vasut , Masahiro Yamada , Masami Hiramatsu , Chuanxiao Dong , Jassi Brar , Brian Norris , David Woodhouse , Rob Herring , Graham Moore MIME-Version: 1.0 Sender: "linux-mtd" Errors-To: linux-mtd-bounces+patch=linaro.org@lists.infradead.org Commit 66507c7bc889 ("mtd: nand: Add support to use nand_base poi databuf as bounce buffer") fixed the issue that drivers can be passed with a kmap()'d buffer. This addressed the use_bufpoi = 0 case. When use_bufpoi = 1, chip->buffers->databuf is used. The databuf allocated by nand_scan_tail() is not suitable for DMA due to the offset, sizeof(*chip->buffers). So, drivers using DMA are very likely to end up with setting the NAND_OWN_BUFFERS flag and allocate buffers by themselves. Drivers tend to use devm_k*alloc to simplify the probe failure path, but devm_k*alloc() does not return a cache line aligned buffer. If used, it could violate the DMA-API requirement stated in Documentation/DMA-API.txt: Warnings: Memory coherency operates at a granularity called the cache line width. In order for memory mapped by this API to operate correctly, the mapped region must begin exactly on a cache line boundary and end exactly on one (to prevent two separately mapped regions from sharing a single cache line). To sum up, NAND_OWN_BUFFERS is not very convenient for drivers. nand_scan_tail() can give a separate buffer for each of ecccalc, ecccode, databuf. It is guaranteed kmalloc'ed memory is aligned with ARCH_DMA_MINALIGN. This is enough for most drivers because it is rare that DMA engines require larger alignment than CPU's cache line. Signed-off-by: Masahiro Yamada --- Changes in v2: - Newly added drivers/mtd/nand/nand_base.c | 34 +++++++++++++++++++++++++++------- 1 file changed, 27 insertions(+), 7 deletions(-) -- 2.7.4 ______________________________________________________ Linux MTD discussion mailing list http://lists.infradead.org/mailman/listinfo/linux-mtd/ diff --git a/drivers/mtd/nand/nand_base.c b/drivers/mtd/nand/nand_base.c index e13f959..6fc0422 100644 --- a/drivers/mtd/nand/nand_base.c +++ b/drivers/mtd/nand/nand_base.c @@ -4614,13 +4614,25 @@ int nand_scan_tail(struct mtd_info *mtd) } if (!(chip->options & NAND_OWN_BUFFERS)) { - nbuf = kzalloc(sizeof(*nbuf) + mtd->writesize - + mtd->oobsize * 3, GFP_KERNEL); + nbuf = kzalloc(sizeof(*nbuf), GFP_KERNEL); if (!nbuf) return -ENOMEM; - nbuf->ecccalc = (uint8_t *)(nbuf + 1); - nbuf->ecccode = nbuf->ecccalc + mtd->oobsize; - nbuf->databuf = nbuf->ecccode + mtd->oobsize; + nbuf->ecccalc = kmalloc(mtd->oobsize, GFP_KERNEL); + if (!nbuf->ecccalc) { + ret = -EINVAL; + goto err_free; + } + nbuf->ecccode = kmalloc(mtd->oobsize, GFP_KERNEL); + if (!nbuf->ecccode) { + ret = -EINVAL; + goto err_free; + } + nbuf->databuf = kmalloc(mtd->writesize + mtd->oobsize, + GFP_KERNEL); + if (!nbuf->databuf) { + ret = -EINVAL; + goto err_free; + } chip->buffers = nbuf; } else { @@ -4863,8 +4875,12 @@ int nand_scan_tail(struct mtd_info *mtd) /* Build bad block table */ return chip->scan_bbt(mtd); err_free: - if (!(chip->options & NAND_OWN_BUFFERS)) + if (!(chip->options & NAND_OWN_BUFFERS)) { + kfree(chip->buffers->databuf); + kfree(chip->buffers->ecccode); + kfree(chip->buffers->ecccalc); kfree(chip->buffers); + } return ret; } EXPORT_SYMBOL(nand_scan_tail); @@ -4915,8 +4931,12 @@ void nand_cleanup(struct nand_chip *chip) /* Free bad block table memory */ kfree(chip->bbt); - if (!(chip->options & NAND_OWN_BUFFERS)) + if (!(chip->options & NAND_OWN_BUFFERS)) { + kfree(chip->buffers->databuf); + kfree(chip->buffers->ecccode); + kfree(chip->buffers->ecccalc); kfree(chip->buffers); + } /* Free bad block descriptor memory */ if (chip->badblock_pattern && chip->badblock_pattern->options