From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f45.google.com (mail-wm1-f45.google.com [209.85.128.45]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 70CC63CAE9B for ; Tue, 14 Apr 2026 10:07:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.45 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776161261; cv=none; b=bcW5XCzeaIL/n98y1k5JGMkF3MpMol19mc4ku3FIJFR4Jr7YZ28emvW0ngcbkKZpI0fue+Ln4S1pz8uuD6MEBwknkZIcmUT+HKaNgtPozL4elFU0Dtwpq0+ORuXZ4sU1ORBhh5qFzH9gcftzMndQRuj1NxK4NzIQDTA0Ol5z+co= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776161261; c=relaxed/simple; bh=yxOwe+ZAi8eq+GEsp/IgrfQcj8tR/cps95A8fxqnPMQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=Wmixjgx0Ak0TcotyifiGSTQpRGbb0h+zG3jRWzUs+UMtsuIcsYS2ZBvr92ttRgYMaTs6LXGZ+pkvtJ6UKKNdlw4wZhtF9FKYNiQ5wEAtxOqycKRJ9qMIf1zYf4PpJrPHO5noiu1UQAeWgqg7PSos8bOaI+iFlpJFpUfCjN8MDe4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=hackers.camp; spf=pass smtp.mailfrom=gmail.com; arc=none smtp.client-ip=209.85.128.45 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=hackers.camp Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-wm1-f45.google.com with SMTP id 5b1f17b1804b1-48880947b7dso7320965e9.0 for ; Tue, 14 Apr 2026 03:07:39 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1776161258; x=1776766058; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=a465pWOyvoZU05HiIIPl0LD4EBbwLj19TV803zaD4aE=; b=rV/FVYS+DNVlC43JflrEdIrCWHZcN4qLWNEiU5TuoDYXO4JES5sXFbb3RyB8C+TtCU qnmcyefM1v4V2we7fSPkSECWxZyEvMaCwcjkSSAmIHM/G529HOFrBcWgS6QVP9kK3O7x Epotssg9uXFZW/pfAm1pvWvpz/f/T6oOFUmi3v5hnHjVdomSF/+obhfiiCfvWsGAA2mP VfuhZcgFxEQQt4viWTaOILeRifN8fkJfSLpGfuraPlAYFQ7yUC0sxFNz4Rm4WZ6jcylJ JDtTF7lpk1Hq9Aqt876TZyG0hW/5kgobB7iLyA0L9DAg8sUzeZtaggqqknD+VdbN5UCw OyEQ== X-Gm-Message-State: AOJu0YxDoAPPL58og/Z1Rd3xXEfmawvrkr3x+Y1cZW7cyFoikr/l6QXN g1IysJ00GHWkQXXzpd3d49pRYRxAdApyIRl0ZLojs2TsnBf4GL55L8Dw X-Gm-Gg: AeBDieufpD5S++tOgtR4kCDt+hvFwdn6xIz0lqKx768/UO85zDJ4996e26k88Bn0bTL 4CyzSDk7QYXZHkHuBO9rI7E1dql5nwY/BvxZhgz56GlxGNq5A8/n9BBQUdPhAOH4Bj/UEkUCFII pL60BKr64ePEAc2K0byPWKRNhRgXvcREhbUbnaArf6FaC/KP3BXPz9bqoWifh5II9J+R9P2q3Hr XbmSQws6MRUSBPYEV5ljYz85ahtV68Pyrq6Ay/3m2tYPz9GwLuV4w+0wmB2sMmlJirs9h1OLrtB C7RZc+jxSIchcnVNgWyeTzfwQyo3sf6VWqgMshPMhGD+NM2eZH+kKUuJpZx5O/lVk6iH3jG4lOy S/diD1odQKN/Ed6MHqrdI8JSvagI1Yqm2ul2EtJMqXow6a+zv/Sm462l/Dkok1HmoOBAgcTeyYv GLCYLkILP5zMOnC+jdvY9XoxMjsnnNxxAgtBn4M2BtwW/e7NUNDh7ONcgUoIXvxpq7rTGyjwBMM /w= X-Received: by 2002:a05:600c:524a:b0:488:926e:3ccd with SMTP id 5b1f17b1804b1-488d7f24014mr120661015e9.4.1776161257764; Tue, 14 Apr 2026 03:07:37 -0700 (PDT) Received: from spartian-1.home ([2a01:cb1c:784:2f00:708:2805:7128:7a75]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-488ede1e050sm65870545e9.5.2026.04.14.03.07.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Apr 2026 03:07:37 -0700 (PDT) From: Aurelien DESBRIERES To: linux-fsdevel@vger.kernel.org Cc: linux-kernel@vger.kernel.org, torvalds@linux-foundation.org, willy@infradead.org, djwong@kernel.org, adilger.kernel@dilger.ca, pedro.falcato@gmail.com, xiang@kernel.org, Aurelien DESBRIERES Subject: [PATCH v3 08/12] ftrfs: add CRC32 checksumming and Reed-Solomon FEC skeleton Date: Tue, 14 Apr 2026 14:07:21 +0200 Message-ID: <20260414120726.5713-9-aurelien@hackers.camp> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260414120726.5713-1-aurelien@hackers.camp> References: <20260413230601.525400-1-aurelien@hackers.camp> <20260414120726.5713-1-aurelien@hackers.camp> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Implement data integrity layer: - ftrfs_crc32(): CRC32 wrapper via kernel crc32_le(), used for per-inode and per-superblock checksums - init_gf_tables(): initialize GF(2^8) Galois Field lookup tables (primitive polynomial 0x1d) for Reed-Solomon arithmetic - gf_mul(): GF(2^8) multiplication via log/exp tables - ftrfs_rs_encode(): systematic Reed-Solomon encoder over FTRFS_SUBBLOCK_DATA bytes with FTRFS_RS_PARITY check symbols The RS encoder operates on sub-blocks within each 4096-byte data block. Decoding (error correction) is not yet implemented. Signed-off-by: Aurelien DESBRIERES --- fs/ftrfs/edac.c | 84 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100644 fs/ftrfs/edac.c diff --git a/fs/ftrfs/edac.c b/fs/ftrfs/edac.c new file mode 100644 index 000000000000..ebe676c98be6 --- /dev/null +++ b/fs/ftrfs/edac.c @@ -0,0 +1,84 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * FTRFS — EDAC layer: CRC32 + Reed-Solomon FEC + * Author: roastercode - Aurelien DESBRIERES + */ + +#include +#include +#include +#include "ftrfs.h" + +/* Reed-Solomon FEC context */ +static uint8_t gf_exp[256]; +static uint8_t gf_log[256]; +static bool rs_initialized; + +/* Initialize Galois Field tables */ +static void init_gf_tables(void) +{ + uint8_t x = 1; + + for (int i = 0; i < 255; i++) { + gf_exp[i] = x; + gf_log[x] = i; + x = (x << 1) ^ ((x & 0x80) ? 0x1d : 0); + } + gf_exp[255] = gf_exp[0]; + rs_initialized = true; +} + +/* Galois Field multiplication */ +static uint8_t gf_mul(uint8_t a, uint8_t b) +{ + if (a == 0 || b == 0) + return 0; + return gf_exp[(gf_log[a] + gf_log[b]) % 255]; +} + +/* Reed-Solomon encoding */ +int ftrfs_rs_encode(uint8_t *data, uint8_t *parity) +{ + uint8_t msg[FTRFS_SUBBLOCK_DATA + FTRFS_RS_PARITY]; + + if (!rs_initialized) + init_gf_tables(); + + memset(msg, 0, sizeof(msg)); + memcpy(msg, data, FTRFS_SUBBLOCK_DATA); + + for (int i = 0; i < FTRFS_SUBBLOCK_DATA; i++) { + uint8_t feedback = gf_mul(msg[i], gf_exp[FTRFS_RS_PARITY]); + + if (feedback != 0) { + for (int j = 1; j <= FTRFS_RS_PARITY; j++) + msg[FTRFS_SUBBLOCK_DATA + j - 1] ^= gf_mul(msg[i], gf_exp[j]); + } + } + + memcpy(parity, msg + FTRFS_SUBBLOCK_DATA, FTRFS_RS_PARITY); + return 0; +} + +/* Reed-Solomon decoding (simplified for now) */ +int ftrfs_rs_decode(uint8_t *data, uint8_t *parity) +{ + if (!rs_initialized) + init_gf_tables(); + + /* For now, assume no errors (full decoding to be implemented) */ + return 0; +} + +/* + * ftrfs_crc32 - compute CRC32 checksum + * @buf: data buffer + * @len: length in bytes + * + * Returns CRC32 checksum. Uses kernel's hardware-accelerated CRC32 + * (same as ext4/btrfs). + */ +__u32 ftrfs_crc32(const void *buf, size_t len) +{ + return crc32_le(0xFFFFFFFF, buf, len) ^ 0xFFFFFFFF; +} -- 2.52.0