From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Google-Smtp-Source: AIpwx4+4SyNuPfQbuasFwAmW7E3k/QMWnJngfLR+bftQRoVveu2uRfGE5gOmCNJ2poItAsOYVoEw ARC-Seal: i=1; a=rsa-sha256; t=1524132731; cv=none; d=google.com; s=arc-20160816; b=iMy95HSyxlxHlpvPP9jycyV0ldVO3mA2qleQkgTuHZ0proRR+QQZsBDTdMTWM9wcFj aVqahXEZWH6oLU3A+crugpFLniF//IVbUajKbI5VZfDWASLBX1m5Mv9jaTfP/MgX/dXP Z8okMKkHgEA1K0OVIzChH72ndUeIOtv6NfcDEm8SIzuy0VfAdZwsb5QYaJQvQRqFvn2U 1A5s1iz9dLgbtgvxU7ozAAleXFVHpccu8NFbTo6iL7u1WBqcoPYYqo5IpUBLbIW2iJ6m HHC2eJ1pnQko5WsTknWxfdix/Z8lqS5ffRVN5+ybMQcLOCsoYMe3redy2NMCF3xq1ICk kPaQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-disposition:mime-version:references:subject:cc:to:from:date :user-agent:message-id:delivered-to:list-id:list-subscribe :list-unsubscribe:list-help:list-post:precedence:mailing-list :arc-authentication-results; bh=Zu3n1zz1kf7NK9CQUcvdwVRHh52ViWGanMsweD9Nj6o=; b=nfuk8ZApNO2DNMtUlnkBBVaEv1gH5xZo2B8s+2qTPs7bn6tgCR0qo9/+BfguTbkTP7 7vdNLWlYeTOHDL98P6QSGq2CpjC0dKZ777LHDtSSPYXdy86Jw5FRDgFoBijMPWXIupEi hU+B4OFyGk722o96rHWhTvAsIA1Yh4i/8ZY+XPjZrQNUmWNYC68Py2P+wu/F/aYb10KS H2b1e3sIfdhJ560fFzB3Rr+mH0fCHmueO6k/5qQJBehxHnkXwGIly9uA0ciwAZfP8ZTM V06mmXMbY+5ssUP/6rvxSe6X6l9NFA0RusChblg9ry8QmTvukIplmtBqKzf3BUyBtK44 DngQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of kernel-hardening-return-13057-gregkh=linuxfoundation.org@lists.openwall.com designates 195.42.179.200 as permitted sender) smtp.mailfrom=kernel-hardening-return-13057-gregkh=linuxfoundation.org@lists.openwall.com Authentication-Results: mx.google.com; spf=pass (google.com: domain of kernel-hardening-return-13057-gregkh=linuxfoundation.org@lists.openwall.com designates 195.42.179.200 as permitted sender) smtp.mailfrom=kernel-hardening-return-13057-gregkh=linuxfoundation.org@lists.openwall.com Mailing-List: contact kernel-hardening-help@lists.openwall.com; run by ezmlm List-Post: List-Help: List-Unsubscribe: List-Subscribe: Message-Id: <20180419100935.257180656@linutronix.de> User-Agent: quilt/0.63-1 Date: Thu, 19 Apr 2018 12:04:47 +0200 From: Thomas Gleixner To: LKML Cc: Kees Cook , Segher Boessenkool , Kernel Hardening , Andrew Morton , Boris Brezillon , Richard Weinberger , David Woodhouse , Alasdair Kergon , Mike Snitzer , Anton Vorontsov , Colin Cross , Tony Luck Subject: [patch V2 6/8] mtd/diskonchip: Allocate rs control per instance References: <20180419100441.548834519@linutronix.de> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Disposition: inline; filename=mtd-diskonchip--Allocate_rs_control_per_instance.patch X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: =?utf-8?q?1598169002744283226?= X-GMAIL-MSGID: =?utf-8?q?1598169002744283226?= X-Mailing-List: linux-kernel@vger.kernel.org List-ID: From: Thomas Gleixner The reed solomon library is moving the on stack decoder buffers into the rs control structure. That would break the DoC driver because multiple instances share the same control structure and can operate in parallel. At least in theory.... Instantiate a rs control instance per DoC device to avoid that. The per instance buffer is fine as the operation on a single DoC instance is serialized by the MTD/NAND core. Signed-off-by: Thomas Gleixner Cc: Boris Brezillon Cc: Tony Luck Cc: Kees Cook Cc: Segher Boessenkool Cc: Kernel Hardening Cc: Richard Weinberger Cc: Mike Snitzer Cc: Anton Vorontsov Cc: Colin Cross Cc: Andrew Morton Cc: David Woodhouse Cc: Alasdair Kergon --- drivers/mtd/nand/raw/diskonchip.c | 60 +++++++++++++++++--------------------- 1 file changed, 27 insertions(+), 33 deletions(-) --- a/drivers/mtd/nand/raw/diskonchip.c +++ b/drivers/mtd/nand/raw/diskonchip.c @@ -66,6 +66,7 @@ struct doc_priv { int curchip; int mh0_page; int mh1_page; + struct rs_control *rs_decoder; struct mtd_info *nextdoc; /* Handle the last stage of initialization (BBT scan, partitioning) */ @@ -123,9 +124,6 @@ MODULE_PARM_DESC(doc_config_location, "P /* Number of symbols */ #define NN 1023 -/* the Reed Solomon control structure */ -static struct rs_control *rs_decoder; - /* * The HW decoder in the DoC ASIC's provides us a error syndrome, * which we must convert to a standard syndrome usable by the generic @@ -931,7 +929,7 @@ static int doc200x_correct_data(struct m calc_ecc[i] = ReadDOC_(docptr, DoC_ECCSyndrome0 + i); } - ret = doc_ecc_decode(rs_decoder, dat, calc_ecc); + ret = doc_ecc_decode(doc->rs_decoder, dat, calc_ecc); if (ret > 0) pr_err("doc200x_correct_data corrected %d errors\n", ret); @@ -1422,10 +1420,10 @@ static inline int __init doc2001plus_ini static int __init doc_probe(unsigned long physadr) { + struct nand_chip *nand = NULL; + struct doc_priv *doc = NULL; unsigned char ChipID; struct mtd_info *mtd; - struct nand_chip *nand; - struct doc_priv *doc; void __iomem *virtadr; unsigned char save_control; unsigned char tmp, tmpb, tmpc; @@ -1562,8 +1560,25 @@ static int __init doc_probe(unsigned lon goto fail; } + + /* + * Allocate a RS codec instance + * + * Symbolsize is 10 (bits) + * Primitve polynomial is x^10+x^3+1 + * First consecutive root is 510 + * Primitve element to generate roots = 1 + * Generator polinomial degree = 4 + */ + doc = (struct doc_priv *) (nand + 1); + doc->rs_decoder = init_rs(10, 0x409, FCR, 1, NROOTS); + if (!doc->rs_decoder) { + pr_err("DiskOnChip: Could not create a RS codec\n"); + ret = -ENOMEM; + goto fail; + } + mtd = nand_to_mtd(nand); - doc = (struct doc_priv *) (nand + 1); nand->bbt_td = (struct nand_bbt_descr *) (doc + 1); nand->bbt_md = nand->bbt_td + 1; @@ -1613,7 +1628,6 @@ static int __init doc_probe(unsigned lon haven't yet added it. This is handled without incident by mtd_device_unregister, as far as I can tell. */ nand_release(mtd); - kfree(nand); goto fail; } @@ -1626,6 +1640,9 @@ static int __init doc_probe(unsigned lon actually a DiskOnChip. */ WriteDOC(save_control, virtadr, DOCControl); fail: + if (doc) + free_rs(doc->rs_decoder); + kfree(nand); iounmap(virtadr); error_ioremap: @@ -1648,6 +1665,7 @@ static void release_nanddoc(void) nand_release(mtd); iounmap(doc->virtadr); release_mem_region(doc->physadr, DOC_IOREMAP_LEN); + free_rs(doc->rs_decoder); kfree(nand); } } @@ -1656,27 +1674,12 @@ static int __init init_nanddoc(void) { int i, ret = 0; - /* We could create the decoder on demand, if memory is a concern. - * This way we have it handy, if an error happens - * - * Symbolsize is 10 (bits) - * Primitve polynomial is x^10+x^3+1 - * first consecutive root is 510 - * primitve element to generate roots = 1 - * generator polinomial degree = 4 - */ - rs_decoder = init_rs(10, 0x409, FCR, 1, NROOTS); - if (!rs_decoder) { - pr_err("DiskOnChip: Could not create a RS decoder\n"); - return -ENOMEM; - } - if (doc_config_location) { pr_info("Using configured DiskOnChip probe address 0x%lx\n", doc_config_location); ret = doc_probe(doc_config_location); if (ret < 0) - goto outerr; + return ret; } else { for (i = 0; (doc_locations[i] != 0xffffffff); i++) { doc_probe(doc_locations[i]); @@ -1687,11 +1690,7 @@ static int __init init_nanddoc(void) if (!doclist) { pr_info("No valid DiskOnChip devices found\n"); ret = -ENODEV; - goto outerr; } - return 0; - outerr: - free_rs(rs_decoder); return ret; } @@ -1699,11 +1698,6 @@ static void __exit cleanup_nanddoc(void) { /* Cleanup the nand/DoC resources */ release_nanddoc(); - - /* Free the reed solomon resources */ - if (rs_decoder) { - free_rs(rs_decoder); - } } module_init(init_nanddoc);