From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1794064156; b=U7oW6GtkTFCW0EkX54QkPHy9QJHF+p4CzocEzcijZFlcH3JXbyIZHTTfW7VQuRvjwcpw 3pcPIthWwBUOUhl77zN+RRp6yr3iaYcHONJXB2KB3gLfH8edYRVEmlupDGpU6HUOoVg1Y LFoJK5M8U+aDTOkgq15tRCAaC6tVmAF0PgK15H3AlHGiDcIUbkPdJVVtondv2Fndy4PJP LqB049mChWiqcI0aIFa99xmUbFO9XBD/OJ/CiprF32OxlT4GVQ4E6DaoB9wkIqq077nxV yJBJCtBJ5vFkcHJznXe0xQAUug72SjH8R+mo44ErNE1vG1/sAEt1RYeMr8TarZHI7cA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1794064156; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Transfer-Encoding; bh=1/0gx5JNgKOeFi3iOBp72JhyvREJVdkWECYN0igeXQM=; b=Z2bgLLS03QbY/m3dGX8LYhrVIEPftva5RWn4RA02IjNJDeXH2B7p8fqYd2UvQm2q8QlK 3Be49XyZXEmFUZguzdgonmml2wWw/knPawnc+Eg+WOUVZuesiVhUjwA9oMIIDyzVqtvjd YjKgYYtdHes1A2dmH2fivsccZj6DoxTLb4IAuxd+NIPYq0AtdJtQAH4DgbAaDhY+MeoyO B62lvldZSiHZbcMmmp9aU8/44fbhE6Cqi8xC9s0Sz5KhZ/4ypFG5963Q/arSkfiKPf6EH iUvgiUIxIveMkNpmEkj5+qhb1phBMheI3ncTeG3MAxS4Vj8J/uz7E4W61MXnJ318eCQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=ZhpCDgJo; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 57214606A32E; Sat, 7 Nov 2026 15:09:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=ZhpCDgJo Received: by smtp.kernel.org (Postfix) with ESMTPSA id 044F31F008A3; Sat, 7 Nov 2026 15:09:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1794064156; bh=1/0gx5JNgKOeFi3iOBp72JhyvREJVdkWECYN0igeXQM=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=ZhpCDgJofXzphzdVKUe/LsTwbvydSe/RGdnEEztzfmMiUf5j6F9i0SAVO1KBa9pFP OIJ/rnymZDIZ3T0X0m8b4+eWj8epi931hBP5Mi7h8tyJMGBiJc/rB2gPDbZV5EUL/q LtdfDg/hQUcK7k2qAGS52UOnADg6S4uh0lBFd+u8= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Orgad Shaneh , Miquel Raynal , Sasha Levin Subject: [PATCH 7.3 0305/1257] mtd: cfi_cmdset_0002: cap the write-buffer chunk at 256 bytes on an x8 device Date: Sat, 7 Nov 2026 08:43:21 -0500 Message-ID: <20261107134947.870899684@linuxfoundation.org> X-Mailer: git-send-email 2.56.0 In-Reply-To: <20261107134939.434104957@linuxfoundation.org> References: <20261107134939.434104957@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: stable@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 7.3-stable review patch. If anyone has any objections, please let me know. ------------------ From: Orgad Shaneh [ Upstream commit cfc5ebc9540e29f8f96db88bbfa261139e5afedb ] The Write to Buffer command takes the number of words to program minus one, and do_write_buffer() sends that count as a single bus word: map_write(map, CMD(words - 1), cmd_adr); CMD() replicates the value into every device lane, so each device reads the count off its own data lines - eight of them on an x8 part. A count that does not fit in eight bits is truncated there, which limits one Write to Buffer to 256 words on an x8 device, however large a buffer the chip advertises in its CFI query. The M29EW on a Cavium Octeon CN6335 board (an x16 part strapped to x8) advertises MaxBufWriteSize = 512 bytes, so cfi_amdstd_write_buffers() split the data into 512-byte chunks and do_write_buffer() sent a count of 511. The chip saw 511 & 0xff = 255, expected 256 bytes, and aborted the program when the 257th arrived. Chunks below 256 bytes - the leading partial chunk of a write - completed normally, so only the full-size ones failed: MTD do_write_buffer_wait(): software timeout, address:0x03278bff. jffs2: Write of 4164 bytes at 0x02c789b4 failed. returned -5, retlen 68 jffs2: No space for garbage collection. Aborting GC thread Clamp MaxBufWriteSize for x8 devices in the write-buffer fixup, and recompute mtd->writebufsize, which cfi_cmdset_0002_setup() derives from MaxBufWriteSize before the fixups run. The clamp deliberately keys off the device width rather than the part, even though the driver already recognises this one in is_m29ew(): the ceiling comes from the width of a device's data bus, not from the chip, so any x8 device advertising a larger buffer is told a count it cannot receive. The M29EW is only where it was found. Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2") Cc: stable@vger.kernel.org Assisted-by: Claude:claude-opus-5 Signed-off-by: Orgad Shaneh Signed-off-by: Miquel Raynal Signed-off-by: Sasha Levin --- drivers/mtd/chips/cfi_cmdset_0002.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/drivers/mtd/chips/cfi_cmdset_0002.c b/drivers/mtd/chips/cfi_cmdset_0002.c index 517db2f2707f4..100cab95a17b1 100644 --- a/drivers/mtd/chips/cfi_cmdset_0002.c +++ b/drivers/mtd/chips/cfi_cmdset_0002.c @@ -283,6 +283,21 @@ static void fixup_use_write_buffers(struct mtd_info *mtd) pr_debug("Using buffer write method\n"); mtd->_write = cfi_amdstd_write_buffers; } + + /* + * The word count of the Write to Buffer command is a single bus + * word per device, so an x8 device can be told to program at most + * 256 bytes however large a buffer it advertises - including when + * several of them are interleaved on a wider bus, where CMD() + * replicates the count into each device's lane and it is truncated + * there. + */ + if (cfi->device_type == CFI_DEVICETYPE_X8 && + cfi->cfiq->MaxBufWriteSize > 8) { + cfi->cfiq->MaxBufWriteSize = 8; + mtd->writebufsize = cfi_interleave(cfi) << + cfi->cfiq->MaxBufWriteSize; + } } #endif /* !FORCE_WORD_WRITE */ -- 2.53.0