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=1795058307; b=RTEmjYBYHWcJU1LCicfIeu2FpBfKB2anuZlUKlQEMrhUvn/4c1O5+Ml5g17nsrwnrmwj 0LKtJ3apM/ZyZtQjNGhcl5iUfSCTIXWSAPtF9LNR2UF4xz5jMgwPON5061sSrU069ovPH dgiWwC53klUSbGv/qlFrVwqnpMzKLhlqjzZY0VnYnt7lIG6LLZNuxGrHJrZ9bJoibmQkr JJxXYTOU9UWurAIj9WZuZdPT0aO17HYIGCM2QGuhoM4Y14/YdP0f+Bp6CbmJgDiHUosQU DoJbf4ipxHriLVpz8gQYt23OwLv2T7xa/o6QcKaO+6JkwrYA/hDydKShKl3o5XG4ENA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795058307; 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=fjsqOr7ElE+6OcI95DpvwC1v23T3CbQQZKqNAh9lkoQ=; b=yibP6KmgBOM1ezMrvoTaJFmm/WOzyfmfNeu7X1Purje3+lXiAWLrwcP5f2EgbX/8qHyU qikUDx+ogF1thnE56M1hEedhQ1F1gycdAKYV8hpaBLj3QnLLEnsSu5XFtBfdkzeqHIPiM 7rsFr45sGxxYJXzLrqAffO9inkG6Jo3uvK2wuSVPDr6gMTYxCi79PrLWOmLuoSU3Upm44 V+WjJ+6578oKRK7OycK5Aheqj2p63MViM72FP+8REYhjzExzP8S6GNtXeI8YG448NjoHO ylaj+Uc1gu0e5AoNlhn1J7BdZ3JhI1mhdg6iOYf2MJkHlhv9mOybG5xjClBdLtFrJTA== 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=fE9W7aq6; 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 21B33606A31C; Thu, 19 Nov 2026 03:18:27 +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=fE9W7aq6 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6FF401F000C4; Thu, 19 Nov 2026 03:18:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1795058307; bh=fjsqOr7ElE+6OcI95DpvwC1v23T3CbQQZKqNAh9lkoQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=fE9W7aq6nVRaN7UtA0YVq3GzKNVyfoiLMW5M7bijROqhIOGeir0qmmeLwQvwNfFvo XDqYwVFoRkx7vo2ecVaj+WaN8pTlw//kXBT1jDkFzlOzu38OPmDehDz+bEibadfEtR HrFY/GnnVCUhrx/RBXrYGWPZ0nwSQstfsAzjw67k= 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 5.10 0437/1848] mtd: cfi_cmdset_0002: cap the write-buffer chunk at 256 bytes on an x8 device Date: Wed, 18 Nov 2026 15:41:15 +0100 Message-ID: <20261118145932.387204698@linuxfoundation.org> X-Mailer: git-send-email 2.56.0 In-Reply-To: <20261118145911.150052362@linuxfoundation.org> References: <20261118145911.150052362@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 5.10-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 9bd65f3f805c0..9065a73f915bf 100644 --- a/drivers/mtd/chips/cfi_cmdset_0002.c +++ b/drivers/mtd/chips/cfi_cmdset_0002.c @@ -280,6 +280,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