get:
Show a patch.

patch:
Update a patch.

put:
Update a patch.

GET /api/1.2/patches/2222816/?format=api
HTTP 200 OK
Allow: GET, PUT, PATCH, HEAD, OPTIONS
Content-Type: application/json
Vary: Accept

{
    "id": 2222816,
    "url": "http://patchwork.ozlabs.org/api/1.2/patches/2222816/?format=api",
    "web_url": "http://patchwork.ozlabs.org/project/linux-cifs-client/patch/20260413190713.283939-5-ematsumiya@suse.de/",
    "project": {
        "id": 12,
        "url": "http://patchwork.ozlabs.org/api/1.2/projects/12/?format=api",
        "name": "Linux CIFS Client",
        "link_name": "linux-cifs-client",
        "list_id": "linux-cifs.vger.kernel.org",
        "list_email": "linux-cifs@vger.kernel.org",
        "web_url": "",
        "scm_url": "",
        "webscm_url": "",
        "list_archive_url": "",
        "list_archive_url_format": "",
        "commit_url_format": ""
    },
    "msgid": "<20260413190713.283939-5-ematsumiya@suse.de>",
    "list_archive_url": null,
    "date": "2026-04-13T19:07:10",
    "name": "[5/8] smb: client: compress: LZ77 optimizations",
    "commit_ref": null,
    "pull_url": null,
    "state": "new",
    "archived": false,
    "hash": "77285eab8dbc565ea1850742d328702827c01250",
    "submitter": {
        "id": 78375,
        "url": "http://patchwork.ozlabs.org/api/1.2/people/78375/?format=api",
        "name": "Enzo Matsumiya",
        "email": "ematsumiya@suse.de"
    },
    "delegate": null,
    "mbox": "http://patchwork.ozlabs.org/project/linux-cifs-client/patch/20260413190713.283939-5-ematsumiya@suse.de/mbox/",
    "series": [
        {
            "id": 499741,
            "url": "http://patchwork.ozlabs.org/api/1.2/series/499741/?format=api",
            "web_url": "http://patchwork.ozlabs.org/project/linux-cifs-client/list/?series=499741",
            "date": "2026-04-13T19:07:09",
            "name": "[1/8] smb: client: compress: fix buffer overrun in lz77_compress()",
            "version": 1,
            "mbox": "http://patchwork.ozlabs.org/series/499741/mbox/"
        }
    ],
    "comments": "http://patchwork.ozlabs.org/api/patches/2222816/comments/",
    "check": "pending",
    "checks": "http://patchwork.ozlabs.org/api/patches/2222816/checks/",
    "tags": {},
    "related": [],
    "headers": {
        "Return-Path": "\n <linux-cifs+bounces-10779-incoming=patchwork.ozlabs.org@vger.kernel.org>",
        "X-Original-To": [
            "incoming@patchwork.ozlabs.org",
            "linux-cifs@vger.kernel.org"
        ],
        "Delivered-To": "patchwork-incoming@legolas.ozlabs.org",
        "Authentication-Results": [
            "legolas.ozlabs.org;\n\tdkim=pass (1024-bit key;\n unprotected) header.d=suse.de header.i=@suse.de header.a=rsa-sha256\n header.s=susede2_rsa header.b=tCvwpcOU;\n\tdkim=pass header.d=suse.de header.i=@suse.de header.a=ed25519-sha256\n header.s=susede2_ed25519 header.b=hkIMDIAs;\n\tdkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de\n header.a=rsa-sha256 header.s=susede2_rsa header.b=tCvwpcOU;\n\tdkim=neutral header.d=suse.de header.i=@suse.de header.a=ed25519-sha256\n header.s=susede2_ed25519 header.b=hkIMDIAs;\n\tdkim-atps=neutral",
            "legolas.ozlabs.org;\n spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org\n (client-ip=2600:3c04:e001:36c::12fc:5321; helo=tor.lore.kernel.org;\n envelope-from=linux-cifs+bounces-10779-incoming=patchwork.ozlabs.org@vger.kernel.org;\n receiver=patchwork.ozlabs.org)",
            "smtp.subspace.kernel.org;\n\tdkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de\n header.b=\"tCvwpcOU\";\n\tdkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de\n header.b=\"hkIMDIAs\";\n\tdkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de\n header.b=\"tCvwpcOU\";\n\tdkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de\n header.b=\"hkIMDIAs\"",
            "smtp.subspace.kernel.org;\n arc=none smtp.client-ip=195.135.223.131",
            "smtp.subspace.kernel.org;\n dmarc=pass (p=none dis=none) header.from=suse.de",
            "smtp.subspace.kernel.org;\n spf=pass smtp.mailfrom=suse.de",
            "smtp-out2.suse.de;\n\tdkim=pass header.d=suse.de header.s=susede2_rsa header.b=tCvwpcOU;\n\tdkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=hkIMDIAs"
        ],
        "Received": [
            "from tor.lore.kernel.org (tor.lore.kernel.org\n [IPv6:2600:3c04:e001:36c::12fc:5321])\n\t(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)\n\t key-exchange x25519 server-signature ECDSA (secp384r1) server-digest SHA384)\n\t(No client certificate requested)\n\tby legolas.ozlabs.org (Postfix) with ESMTPS id 4fvcR53cR6z1y2d\n\tfor <incoming@patchwork.ozlabs.org>; Tue, 14 Apr 2026 05:09:37 +1000 (AEST)",
            "from smtp.subspace.kernel.org (conduit.subspace.kernel.org\n [100.90.174.1])\n\tby tor.lore.kernel.org (Postfix) with ESMTP id 2AAA13024A24\n\tfor <incoming@patchwork.ozlabs.org>; Mon, 13 Apr 2026 19:08:05 +0000 (UTC)",
            "from localhost.localdomain (localhost.localdomain [127.0.0.1])\n\tby smtp.subspace.kernel.org (Postfix) with ESMTP id 81AD11A3166;\n\tMon, 13 Apr 2026 19:08:02 +0000 (UTC)",
            "from smtp-out2.suse.de (smtp-out2.suse.de [195.135.223.131])\n\t(using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits))\n\t(No client certificate requested)\n\tby smtp.subspace.kernel.org (Postfix) with ESMTPS id E90EE3451B2\n\tfor <linux-cifs@vger.kernel.org>; Mon, 13 Apr 2026 19:08:00 +0000 (UTC)",
            "from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org\n [IPv6:2a07:de40:b281:104:10:150:64:97])\n\t(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)\n\t key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest\n SHA256)\n\t(No client certificate requested)\n\tby smtp-out2.suse.de (Postfix) with ESMTPS id 4D5075BDAE;\n\tMon, 13 Apr 2026 19:07:59 +0000 (UTC)",
            "from imap1.dmz-prg2.suse.org (localhost [127.0.0.1])\n\t(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)\n\t key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest\n SHA256)\n\t(No client certificate requested)\n\tby imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id CC2424B039;\n\tMon, 13 Apr 2026 19:07:58 +0000 (UTC)",
            "from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167])\n\tby imap1.dmz-prg2.suse.org with ESMTPSA\n\tid jgxAJA4/3Wm4EAAAD6G6ig\n\t(envelope-from <ematsumiya@suse.de>); Mon, 13 Apr 2026 19:07:58 +0000"
        ],
        "ARC-Seal": "i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116;\n\tt=1776107282; cv=none;\n b=jT7duGy2nob1ZZ0SipvyYPu4WvkntkATi/pKl0qt1a4T/DXfe8vbe8MaROFvHrBE/Bg8XfMtTDGxXCKtbalms5bFpLZiASLVJ2RUsAgKGZm9LcUInRh+Gfs3CieguI1R1FXH8sYdc/Hv+xkqvwikM/kLvXgqo1jMRPqYdoxaWF0=",
        "ARC-Message-Signature": "i=1; a=rsa-sha256; d=subspace.kernel.org;\n\ts=arc-20240116; t=1776107282; c=relaxed/simple;\n\tbh=bYivK3gZhsGgdNoAUWS1izuFxzT4vWHPYqi9PhN8ie8=;\n\th=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References:\n\t MIME-Version;\n b=SoxXYOCY2vWW0gH3Wz4w2WvTKDhLGqmmXmj2jj1AoYnzkszawIoz1EYQJrNv+TwgR6Ou9z+xBValt3kXZeSqYSzZ0jzClGueNSIWFaNAS29reqX2YGJbxwZ+n+exBSIick4uO8dPoeGtygpZThd0ohDqn0JRBFL1clUmwxxsfgE=",
        "ARC-Authentication-Results": "i=1; smtp.subspace.kernel.org;\n dmarc=pass (p=none dis=none) header.from=suse.de;\n spf=pass smtp.mailfrom=suse.de;\n dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de\n header.b=tCvwpcOU;\n dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de\n header.b=hkIMDIAs;\n dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de\n header.b=tCvwpcOU;\n dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de\n header.b=hkIMDIAs; arc=none smtp.client-ip=195.135.223.131",
        "DKIM-Signature": [
            "v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de;\n s=susede2_rsa;\n\tt=1776107279;\n h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc:\n\t mime-version:mime-version:\n\t content-transfer-encoding:content-transfer-encoding:\n\t in-reply-to:in-reply-to:references:references;\n\tbh=5MkbUwX5Hev4qpFGKHQ4CvdhNmiSmmV3TbWd349AfXw=;\n\tb=tCvwpcOUJWUJx+8YjotsA/4OSaZ/Yq5LUtgynTpWqxN1R5vyGzQr8t2r8Wgs0w00LblP7S\n\tomc4Hu1UkwyV1PquQYA4YJ22LZRqjmYbKH0jVJIwitReYEJf1rm+8VPqzfWEtWLLGN+SHx\n\tpke4utx7sQOZAUCBv4+tW98dJ8UNsu0=",
            "v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de;\n\ts=susede2_ed25519; t=1776107279;\n\th=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc:\n\t mime-version:mime-version:\n\t content-transfer-encoding:content-transfer-encoding:\n\t in-reply-to:in-reply-to:references:references;\n\tbh=5MkbUwX5Hev4qpFGKHQ4CvdhNmiSmmV3TbWd349AfXw=;\n\tb=hkIMDIAscSBXLB0u14XV6C22qq57I8RJPU70tU5O+varEH2rAgEQCEIYhLevlY5KnAUkNP\n\tt/XfCtOZwNm/WCBw==",
            "v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de;\n s=susede2_rsa;\n\tt=1776107279;\n h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc:\n\t mime-version:mime-version:\n\t content-transfer-encoding:content-transfer-encoding:\n\t in-reply-to:in-reply-to:references:references;\n\tbh=5MkbUwX5Hev4qpFGKHQ4CvdhNmiSmmV3TbWd349AfXw=;\n\tb=tCvwpcOUJWUJx+8YjotsA/4OSaZ/Yq5LUtgynTpWqxN1R5vyGzQr8t2r8Wgs0w00LblP7S\n\tomc4Hu1UkwyV1PquQYA4YJ22LZRqjmYbKH0jVJIwitReYEJf1rm+8VPqzfWEtWLLGN+SHx\n\tpke4utx7sQOZAUCBv4+tW98dJ8UNsu0=",
            "v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de;\n\ts=susede2_ed25519; t=1776107279;\n\th=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc:\n\t mime-version:mime-version:\n\t content-transfer-encoding:content-transfer-encoding:\n\t in-reply-to:in-reply-to:references:references;\n\tbh=5MkbUwX5Hev4qpFGKHQ4CvdhNmiSmmV3TbWd349AfXw=;\n\tb=hkIMDIAscSBXLB0u14XV6C22qq57I8RJPU70tU5O+varEH2rAgEQCEIYhLevlY5KnAUkNP\n\tt/XfCtOZwNm/WCBw=="
        ],
        "From": "Enzo Matsumiya <ematsumiya@suse.de>",
        "To": "linux-cifs@vger.kernel.org",
        "Cc": "smfrench@gmail.com,\n\tpc@manguebit.com,\n\tronniesahlberg@gmail.com,\n\tsprasad@microsoft.com,\n\ttom@talpey.com,\n\tbharathsm@microsoft.com,\n\thenrique.carvalho@suse.com",
        "Subject": "[PATCH 5/8] smb: client: compress: LZ77 optimizations",
        "Date": "Mon, 13 Apr 2026 16:07:10 -0300",
        "Message-ID": "<20260413190713.283939-5-ematsumiya@suse.de>",
        "X-Mailer": "git-send-email 2.53.0",
        "In-Reply-To": "<20260413190713.283939-1-ematsumiya@suse.de>",
        "References": "<20260413190713.283939-1-ematsumiya@suse.de>",
        "Precedence": "bulk",
        "X-Mailing-List": "linux-cifs@vger.kernel.org",
        "List-Id": "<linux-cifs.vger.kernel.org>",
        "List-Subscribe": "<mailto:linux-cifs+subscribe@vger.kernel.org>",
        "List-Unsubscribe": "<mailto:linux-cifs+unsubscribe@vger.kernel.org>",
        "MIME-Version": "1.0",
        "Content-Transfer-Encoding": "8bit",
        "X-Spamd-Result": "default: False [-3.01 / 50.00];\n\tBAYES_HAM(-3.00)[100.00%];\n\tNEURAL_HAM_LONG(-1.00)[-1.000];\n\tMID_CONTAINS_FROM(1.00)[];\n\tR_MISSING_CHARSET(0.50)[];\n\tR_DKIM_ALLOW(-0.20)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519];\n\tNEURAL_HAM_SHORT(-0.20)[-1.000];\n\tMIME_GOOD(-0.10)[text/plain];\n\tMX_GOOD(-0.01)[];\n\tTO_MATCH_ENVRCPT_ALL(0.00)[];\n\tRCVD_VIA_SMTP_AUTH(0.00)[];\n\tFUZZY_RATELIMITED(0.00)[rspamd.com];\n\tFREEMAIL_CC(0.00)[gmail.com,manguebit.com,microsoft.com,talpey.com,suse.com];\n\tARC_NA(0.00)[];\n\tMIME_TRACE(0.00)[0:+];\n\tFREEMAIL_ENVRCPT(0.00)[gmail.com];\n\tRCVD_COUNT_TWO(0.00)[2];\n\tFROM_EQ_ENVFROM(0.00)[];\n\tRCPT_COUNT_SEVEN(0.00)[8];\n\tDKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519];\n\tRCVD_TLS_ALL(0.00)[];\n\tTO_DN_NONE(0.00)[];\n\tFROM_HAS_DN(0.00)[];\n\tDBL_BLOCKED_OPENRESOLVER(0.00)[suse.de:mid,suse.de:dkim,suse.de:email];\n\tDKIM_TRACE(0.00)[suse.de:+]",
        "X-Rspamd-Action": "no action",
        "X-Spam-Flag": "NO",
        "X-Spam-Score": "-3.01",
        "X-Spam-Level": "",
        "X-Rspamd-Server": "rspamd1.dmz-prg2.suse.org",
        "X-Rspamd-Queue-Id": "4D5075BDAE"
    },
    "content": "This patch implements several micro-optimizations on lz77_compress()\nwith the goal of reducing the number of instructions per [input]\nbyte (a.k.a. IPB).\n\nChanges:\n- change hashtable to be u32 (instead of u64) -- change the hash\n  function to reflect that (adds lz77_hash() and lz77_read32() helpers)\n- batch-write literals instead of 1 by 1 -- now that we have a well\n  defined hot path (match finding) and a cold path (encode literals +\n  match), batch writing makes a significant difference\n- implement adaptive skipping of input bytes -- skip input bytes more\n  aggressively if too few matches are being found\n- name some constants for more meaningful context\n\nSigned-off-by: Enzo Matsumiya <ematsumiya@suse.de>\n---\n fs/smb/client/compress/lz77.c | 173 +++++++++++++++++++++-------------\n fs/smb/client/compress/lz77.h |   4 +-\n 2 files changed, 108 insertions(+), 69 deletions(-)",
    "diff": "diff --git a/fs/smb/client/compress/lz77.c b/fs/smb/client/compress/lz77.c\nindex 480927dcd4c6..96744f52e364 100644\n--- a/fs/smb/client/compress/lz77.c\n+++ b/fs/smb/client/compress/lz77.c\n@@ -1,6 +1,6 @@\n // SPDX-License-Identifier: GPL-2.0-only\n /*\n- * Copyright (C) 2024, SUSE LLC\n+ * Copyright (C) 2024-2026, SUSE LLC\n  *\n  * Authors: Enzo Matsumiya <ematsumiya@suse.de>\n  *\n@@ -16,17 +16,26 @@\n /*\n  * Compression parameters.\n  */\n-#define LZ77_MATCH_MIN_LEN\t4\n #define LZ77_MATCH_MAX_DIST\tSZ_8K\n #define LZ77_HASH_LOG\t\t15\n #define LZ77_HASH_SIZE\t\t(1 << LZ77_HASH_LOG)\n-#define LZ77_STEP_SIZE\t\tsizeof(u64)\n+#define LZ77_RSTEP_SIZE\t\tsizeof(u32)\n+#define LZ77_MSTEP_SIZE\t\tsizeof(u64)\n+#define LZ77_SKIP_TRIGGER\t4\n+\n+#define LZ77_PREFETCH(ptr)\t__builtin_prefetch((ptr), 0, 3)\n+#define LZ77_FLAG_MAX\t\t32\n \n static __always_inline u8 lz77_read8(const u8 *ptr)\n {\n \treturn get_unaligned(ptr);\n }\n \n+static __always_inline u32 lz77_read32(const u32 *ptr)\n+{\n+\treturn get_unaligned(ptr);\n+}\n+\n static __always_inline u64 lz77_read64(const u64 *ptr)\n {\n \treturn get_unaligned(ptr);\n@@ -50,14 +59,14 @@ static __always_inline void lz77_write32(u32 *ptr, u32 v)\n static __always_inline u32 lz77_match_len(const void *match, const void *cur, const void *end)\n {\n \tconst void *start = cur;\n-\tu64 diff;\n \n \t/* Safe for a do/while because otherwise we wouldn't reach here from the main loop. */\n \tdo {\n-\t\tdiff = lz77_read64(cur) ^ lz77_read64(match);\n+\t\tconst u64 diff = lz77_read64(cur) ^ lz77_read64(match);\n+\n \t\tif (!diff) {\n-\t\t\tcur += LZ77_STEP_SIZE;\n-\t\t\tmatch += LZ77_STEP_SIZE;\n+\t\t\tcur += LZ77_MSTEP_SIZE;\n+\t\t\tmatch += LZ77_MSTEP_SIZE;\n \n \t\t\tcontinue;\n \t\t}\n@@ -66,7 +75,7 @@ static __always_inline u32 lz77_match_len(const void *match, const void *cur, co\n \t\tcur += count_trailing_zeros(diff) >> 3;\n \n \t\treturn (cur - start);\n-\t} while (likely(cur + LZ77_STEP_SIZE <= end));\n+\t} while (likely(cur + LZ77_MSTEP_SIZE <= end));\n \n \t/* Fallback to byte-by-byte comparison for last <8 bytes. */\n \twhile (cur < end && lz77_read8(cur) == lz77_read8(match)) {\n@@ -77,7 +86,7 @@ static __always_inline u32 lz77_match_len(const void *match, const void *cur, co\n \treturn (cur - start);\n }\n \n-static __always_inline void *lz77_write_match(void *dst, void **nib, u32 dist, u32 len)\n+static __always_inline void *lz77_encode_match(void *dst, void **nib, u16 dist, u32 len)\n {\n \tlen -= 3;\n \tdist--;\n@@ -131,94 +140,124 @@ static __always_inline void *lz77_write_match(void *dst, void **nib, u32 dist, u\n \treturn dst + 4;\n }\n \n-noinline int lz77_compress(const void *src, u32 slen, void *dst, u32 *dlen)\n+static __always_inline void *lz77_encode_literals(const void *start, const void *end, void *dst,\n+\t\t\t\t\t\t  long *f, u32 *fc, void **fp)\n+{\n+\tif (start >= end)\n+\t\treturn dst;\n+\n+\tdo {\n+\t\tconst u32 len = umin(end - start, LZ77_FLAG_MAX - *fc);\n+\n+\t\tmemcpy(dst, start, len);\n+\n+\t\tdst += len;\n+\t\tstart += len;\n+\n+\t\t*f <<= len;\n+\t\t*fc += len;\n+\t\tif (*fc == LZ77_FLAG_MAX) {\n+\t\t\tlz77_write32(*fp, *f);\n+\t\t\t*fc = 0;\n+\t\t\t*fp = dst;\n+\t\t\tdst += 4;\n+\t\t}\n+\t} while (start < end);\n+\n+\treturn dst;\n+}\n+\n+static __always_inline u32 lz77_hash(const u32 v)\n+{\n+\treturn ((v ^ 0x9E3779B9) * 0x85EBCA6B) >> (32 - LZ77_HASH_LOG);\n+}\n+\n+noinline int lz77_compress(const void *src, const u32 slen, void *dst, u32 *dlen)\n {\n-\tconst void *srcp, *end;\n+\tconst void *srcp, *rlim, *end, *anchor;\n+\tu32 *htable, hash, flag_count = 0;\n \tvoid *dstp, *nib, *flag_pos;\n-\tu32 flag_count = 0;\n \tlong flag = 0;\n-\tu64 *htable;\n \n \t/* This is probably a bug, so throw a warning. */\n \tif (WARN_ON_ONCE(*dlen < lz77_compressed_alloc_size(slen)))\n \t\treturn -EINVAL;\n \n-\tsrcp = src;\n-\tend = src + slen;\n+\tsrcp = anchor = src;\n+\tend = srcp + slen; /* absolute end */\n+\trlim = end - LZ77_MSTEP_SIZE; /* read limit (for lz77_match_len()) */\n \tdstp = dst;\n-\tnib = NULL;\n \tflag_pos = dstp;\n \tdstp += 4;\n+\tnib = NULL;\n \n \thtable = kvcalloc(LZ77_HASH_SIZE, sizeof(*htable), GFP_KERNEL);\n \tif (!htable)\n \t\treturn -ENOMEM;\n \n-\t/* Main loop. */\n-\tdo {\n-\t\tu32 dist, len = 0;\n-\t\tconst void *wnd;\n-\t\tu64 hash;\n-\n-\t\thash = ((lz77_read64(srcp) << 24) * 889523592379ULL) >> (64 - LZ77_HASH_LOG);\n-\t\twnd = src + htable[hash];\n-\t\thtable[hash] = srcp - src;\n-\t\tdist = srcp - wnd;\n-\n-\t\tif (dist && dist < LZ77_MATCH_MAX_DIST)\n-\t\t\tlen = lz77_match_len(wnd, srcp, end);\n+\tLZ77_PREFETCH(srcp + LZ77_RSTEP_SIZE);\n \n-\t\tif (len < LZ77_MATCH_MIN_LEN) {\n-\t\t\tlz77_write8(dstp, lz77_read8(srcp));\n-\n-\t\t\tdstp++;\n-\t\t\tsrcp++;\n-\n-\t\t\tflag <<= 1;\n-\t\t\tflag_count++;\n-\t\t\tif (flag_count == 32) {\n-\t\t\t\tlz77_write32(flag_pos, flag);\n-\t\t\t\tflag_count = 0;\n-\t\t\t\tflag_pos = dstp;\n-\t\t\t\tdstp += 4;\n-\t\t\t}\n-\n-\t\t\tcontinue;\n-\t\t}\n+\thash = lz77_hash(lz77_read32(srcp++));\n+\thtable[hash] = 0;\n+\thash = lz77_hash(lz77_read32(srcp));\n \n-\t\tdstp = lz77_write_match(dstp, &nib, dist, len);\n+\t/*\n+\t * Main loop.\n+\t *\n+\t * @dlen is >= lz77_compressed_alloc_size(), so run without bound-checking @dstp.\n+\t *\n+\t * This code was crafted in a way to best utilise fetch-decode-execute CPU flow.\n+\t * Any attempt to optimize it, or even organize it, can lead to huge performance loss.\n+\t */\n+\tdo {\n+\t\tconst void *match, *next = srcp;\n+\t\tu32 len, step = 1, skip = 1U << LZ77_SKIP_TRIGGER;\n+\n+\t\t/* Match finding (hot path -- don't change the read/check/write order). */\n+\t\tdo {\n+\t\t\tconst u32 cur_hash = hash;\n+\n+\t\t\tsrcp = next;\n+\t\t\tnext += step;\n+\t\t\tstep = (skip++ >> LZ77_SKIP_TRIGGER);\n+\t\t\tif (unlikely(next > rlim))\n+\t\t\t\tgoto out;\n+\n+\t\t\thash = lz77_hash(lz77_read32(next));\n+\t\t\tmatch = src + htable[cur_hash];\n+\t\t\thtable[cur_hash] = srcp - src;\n+\t\t} while (likely(match + LZ77_MATCH_MAX_DIST < srcp) ||\n+\t\t\t lz77_read32(match) != lz77_read32(srcp));\n+\n+\t\tdstp = lz77_encode_literals(anchor, srcp, dstp, &flag, &flag_count, &flag_pos);\n+\t\tlen = lz77_match_len(match, srcp, end);\n+\t\tdstp = lz77_encode_match(dstp, &nib, srcp - match, len);\n \t\tsrcp += len;\n+\t\tanchor = srcp;\n+\n+\t\tLZ77_PREFETCH(srcp);\n \n \t\tflag = (flag << 1) | 1;\n \t\tflag_count++;\n-\t\tif (flag_count == 32) {\n+\t\tif (flag_count == LZ77_FLAG_MAX) {\n \t\t\tlz77_write32(flag_pos, flag);\n \t\t\tflag_count = 0;\n \t\t\tflag_pos = dstp;\n \t\t\tdstp += 4;\n \t\t}\n-\t} while (likely(srcp + LZ77_STEP_SIZE <= end));\n-\n-\twhile (srcp < end) {\n-\t\tu32 c = umin(end - srcp, 32 - flag_count);\n \n-\t\tmemcpy(dstp, srcp, c);\n+\t\tif (unlikely(srcp > rlim))\n+\t\t\tbreak;\n \n-\t\tdstp += c;\n-\t\tsrcp += c;\n-\n-\t\tflag <<= c;\n-\t\tflag_count += c;\n-\t\tif (flag_count == 32) {\n-\t\t\tlz77_write32(flag_pos, flag);\n-\t\t\tflag_count = 0;\n-\t\t\tflag_pos = dstp;\n-\t\t\tdstp += 4;\n-\t\t}\n-\t}\n+\t\t/* Prepare for next loop. */\n+\t\thash = lz77_hash(lz77_read32(srcp));\n+\t} while (srcp < end);\n+out:\n+\tdstp = lz77_encode_literals(anchor, end, dstp, &flag, &flag_count, &flag_pos);\n \n-\tflag <<= (32 - flag_count);\n-\tflag |= (1UL << (32 - flag_count)) - 1;\n+\tflag_count = LZ77_FLAG_MAX - flag_count;\n+\tflag <<= flag_count;\n+\tflag |= (1UL << flag_count) - 1;\n \tlz77_write32(flag_pos, flag);\n \n \t*dlen = dstp - dst;\ndiff --git a/fs/smb/client/compress/lz77.h b/fs/smb/client/compress/lz77.h\nindex 2603eab9e071..4e570846aefa 100644\n--- a/fs/smb/client/compress/lz77.h\n+++ b/fs/smb/client/compress/lz77.h\n@@ -1,6 +1,6 @@\n /* SPDX-License-Identifier: GPL-2.0-only */\n /*\n- * Copyright (C) 2024, SUSE LLC\n+ * Copyright (C) 2024-2026, SUSE LLC\n  *\n  * Authors: Enzo Matsumiya <ematsumiya@suse.de>\n  *\n@@ -39,5 +39,5 @@ static __always_inline u32 lz77_compressed_alloc_size(const u32 size)\n \treturn size + (size >> 3) + 8;\n }\n \n-int lz77_compress(const void *src, u32 slen, void *dst, u32 *dlen);\n+int lz77_compress(const void *src, const u32 slen, void *dst, u32 *dlen);\n #endif /* _SMB_COMPRESS_LZ77_H */\n",
    "prefixes": [
        "5/8"
    ]
}