Patch Detail
get:
Show a patch.
patch:
Update a patch.
put:
Update a patch.
GET /api/1.1/patches/2228139/?format=api
{ "id": 2228139, "url": "http://patchwork.ozlabs.org/api/1.1/patches/2228139/?format=api", "web_url": "http://patchwork.ozlabs.org/project/linux-cifs-client/patch/20260425125426.3855807-18-dhowells@redhat.com/", "project": { "id": 12, "url": "http://patchwork.ozlabs.org/api/1.1/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": "" }, "msgid": "<20260425125426.3855807-18-dhowells@redhat.com>", "date": "2026-04-25T12:54:21", "name": "[v3,17/19] netfs: Fix missing barriers when accessing stream->subrequests locklessly", "commit_ref": null, "pull_url": null, "state": "new", "archived": false, "hash": "4e1a22e9af744e713cbab4742e01dc79f3f52efe", "submitter": { "id": 59, "url": "http://patchwork.ozlabs.org/api/1.1/people/59/?format=api", "name": "David Howells", "email": "dhowells@redhat.com" }, "delegate": null, "mbox": "http://patchwork.ozlabs.org/project/linux-cifs-client/patch/20260425125426.3855807-18-dhowells@redhat.com/mbox/", "series": [ { "id": 501437, "url": "http://patchwork.ozlabs.org/api/1.1/series/501437/?format=api", "web_url": "http://patchwork.ozlabs.org/project/linux-cifs-client/list/?series=501437", "date": "2026-04-25T12:54:04", "name": "netfs: Miscellaneous fixes", "version": 3, "mbox": "http://patchwork.ozlabs.org/series/501437/mbox/" } ], "comments": "http://patchwork.ozlabs.org/api/patches/2228139/comments/", "check": "pending", "checks": "http://patchwork.ozlabs.org/api/patches/2228139/checks/", "tags": {}, "headers": { "Return-Path": "\n <linux-cifs+bounces-11126-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=redhat.com header.i=@redhat.com header.a=rsa-sha256\n header.s=mimecast20190719 header.b=awinhnkn;\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-11126-incoming=patchwork.ozlabs.org@vger.kernel.org;\n receiver=patchwork.ozlabs.org)", "smtp.subspace.kernel.org;\n\tdkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com\n header.b=\"awinhnkn\"", "smtp.subspace.kernel.org;\n arc=none smtp.client-ip=170.10.133.124", "smtp.subspace.kernel.org;\n dmarc=pass (p=quarantine dis=none) header.from=redhat.com", "smtp.subspace.kernel.org;\n spf=pass smtp.mailfrom=redhat.com" ], "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)\n\t(No client certificate requested)\n\tby legolas.ozlabs.org (Postfix) with ESMTPS id 4g2qkl6MZ6z1yJ2\n\tfor <incoming@patchwork.ozlabs.org>; Sat, 25 Apr 2026 23:03:11 +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 E1D0D3086675\n\tfor <incoming@patchwork.ozlabs.org>; Sat, 25 Apr 2026 12:57:06 +0000 (UTC)", "from localhost.localdomain (localhost.localdomain [127.0.0.1])\n\tby smtp.subspace.kernel.org (Postfix) with ESMTP id D28D439900C;\n\tSat, 25 Apr 2026 12:56:03 +0000 (UTC)", "from us-smtp-delivery-124.mimecast.com\n (us-smtp-delivery-124.mimecast.com [170.10.133.124])\n\t(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))\n\t(No client certificate requested)\n\tby smtp.subspace.kernel.org (Postfix) with ESMTPS id D501F39C63E\n\tfor <linux-cifs@vger.kernel.org>; Sat, 25 Apr 2026 12:56:01 +0000 (UTC)", "from mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com\n (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by\n relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3,\n cipher=TLS_AES_256_GCM_SHA384) id us-mta-110-7CyjIUyZM8i-NFPYXkIfiQ-1; Sat,\n 25 Apr 2026 08:55:57 -0400", "from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com\n (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4])\n\t(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)\n\t key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest\n SHA256)\n\t(No client certificate requested)\n\tby mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS\n id 1FD93180034F;\n\tSat, 25 Apr 2026 12:55:56 +0000 (UTC)", "from warthog.procyon.org.com (unknown [10.44.48.17])\n\tby mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP\n id 6AFF2300757C;\n\tSat, 25 Apr 2026 12:55:53 +0000 (UTC)" ], "ARC-Seal": "i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116;\n\tt=1777121763; cv=none;\n b=Bz+5hh4Y4aVNEtO7nYC0Dh1Gagh4Vw5bTMWJzk/qOUjqzgHmXS0FaeyGUYSvSO8h6EGxoWz2w7RPaCBHMEx7ftV/+mm/Wq+huE5a9t3HvfRs5INO6k7YS+ITGfK/vvqQzjT2H/5kE5u3HNZeqxHJYkFi0WMKxWM3v0B2G8KeRoQ=", "ARC-Message-Signature": "i=1; a=rsa-sha256; d=subspace.kernel.org;\n\ts=arc-20240116; t=1777121763; c=relaxed/simple;\n\tbh=5ISMkGKNoZx7CCpTebv8PWFiif0nSO2252s6L20Gm9k=;\n\th=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References:\n\t MIME-Version;\n b=RhMK+jehJVl1l/kLaATFVvnNhLFgbez0n1uu7bxBuwccidJZBXbNpoFSL2VQDRaRYp6kZqG8Nr7XxaS0XHT2Ky+cy0CSwX2AaaiED+gUCAMB+brYHd5pYzEV93QQDRjYTDg1IPbUTB2RFWD4Q8JDJLd4FmurJhR72GUzzNeqamQ=", "ARC-Authentication-Results": "i=1; smtp.subspace.kernel.org;\n dmarc=pass (p=quarantine dis=none) header.from=redhat.com;\n spf=pass smtp.mailfrom=redhat.com;\n dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com\n header.b=awinhnkn; arc=none smtp.client-ip=170.10.133.124", "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com;\n\ts=mimecast20190719; t=1777121761;\n\th=from:from:reply-to:subject:subject:date:date:message-id:message-id:\n\t to:to:cc:cc:mime-version:mime-version:\n\t content-transfer-encoding:content-transfer-encoding:\n\t in-reply-to:in-reply-to:references:references;\n\tbh=kGNOdLG+r8cO2/J2gGfuyvyMT5Ixtk3iTE5O/NcMFjA=;\n\tb=awinhnkngtTx3DYGv9v96I/2PwLJ4TsPnzuUuUZ+uzf3/DJKJnZj0h/6sgRgGpV41RFkQk\n\tXbPGBbBuguZQDQ3odw9BwuWx7swcl1XVRO5BIr+oojnixYzHWeslM39j7iTKSNbIB68Z3Y\n\tBeTB1yuNkK2P64RcCuZbrBcvhxG27zk=", "X-MC-Unique": "7CyjIUyZM8i-NFPYXkIfiQ-1", "X-Mimecast-MFC-AGG-ID": "7CyjIUyZM8i-NFPYXkIfiQ_1777121756", "From": "David Howells <dhowells@redhat.com>", "To": "Christian Brauner <christian@brauner.io>", "Cc": "David Howells <dhowells@redhat.com>,\n\tPaulo Alcantara <pc@manguebit.org>,\n\tnetfs@lists.linux.dev,\n\tlinux-afs@lists.infradead.org,\n\tlinux-cifs@vger.kernel.org,\n\tceph-devel@vger.kernel.org,\n\tlinux-fsdevel@vger.kernel.org,\n\tlinux-kernel@vger.kernel.org", "Subject": "[PATCH v3 17/19] netfs: Fix missing barriers when accessing\n stream->subrequests locklessly", "Date": "Sat, 25 Apr 2026 13:54:21 +0100", "Message-ID": "<20260425125426.3855807-18-dhowells@redhat.com>", "In-Reply-To": "<20260425125426.3855807-1-dhowells@redhat.com>", "References": "<20260425125426.3855807-1-dhowells@redhat.com>", "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-Scanned-By": "MIMEDefang 3.4.1 on 10.30.177.4" }, "content": "The list of subrequests attached to stream->subrequests is accessed without\nlocks by netfs_collect_read_results() and netfs_collect_write_results(),\nbut they access subreq->flags without taking a barrier after getting the\nsubreq pointer from the list. Relatedly, the functions that build the list\ndon't use any sort of write barrier when constructing the list to make sure\nthat the NETFS_SREQ_IN_PROGRESS flag is perceived to be set first if no\nlock is taken.\n\nFix this by:\n\n (1) Add a new list_add_tail_release() function that uses a release barrier\n to set the pointer to the new member of the list.\n\n (2) Add a new list_first_entry_acquire() function that uses an acquire\n barrier to read the pointer to the first member in a list (or return\n NULL).\n\n (3) Use list_add_tail_release() when adding a subreq to ->subrequests.\n\n (4) Make direct-read and read-single use netfs_queue_read() so that they\n share the relevant bit of code with buffered-read.\n\n (5) Use list_first_entry_acquire() when initially accessing the front of\n the list (when an item is removed, the pointer to the new front iterm\n is obtained under the same lock).\n\nFixes: e2d46f2ec332 (\"netfs: Change the read result collector to only use one work item\")\nFixes: 288ace2f57c9 (\"netfs: New writeback implementation\")\nLink: https://sashiko.dev/#/patchset/20260326104544.509518-1-dhowells%40redhat.com\nSigned-off-by: David Howells <dhowells@redhat.com>\ncc: Paulo Alcantara <pc@manguebit.org>\ncc: netfs@lists.linux.dev\ncc: linux-fsdevel@vger.kernel.org\n---\n fs/netfs/buffered_read.c | 9 +++++----\n fs/netfs/direct_read.c | 15 +--------------\n fs/netfs/internal.h | 3 +++\n fs/netfs/read_collect.c | 4 +++-\n fs/netfs/read_single.c | 12 +-----------\n fs/netfs/write_collect.c | 4 +++-\n fs/netfs/write_issue.c | 3 ++-\n include/linux/list.h | 37 +++++++++++++++++++++++++++++++++++++\n 8 files changed, 55 insertions(+), 32 deletions(-)", "diff": "diff --git a/fs/netfs/buffered_read.c b/fs/netfs/buffered_read.c\nindex 2de849bd780f..7e7dacded8f7 100644\n--- a/fs/netfs/buffered_read.c\n+++ b/fs/netfs/buffered_read.c\n@@ -156,9 +156,9 @@ static void netfs_read_cache_to_pagecache(struct netfs_io_request *rreq,\n \t\t\tnetfs_cache_read_terminated, subreq);\n }\n \n-static void netfs_queue_read(struct netfs_io_request *rreq,\n-\t\t\t struct netfs_io_subrequest *subreq,\n-\t\t\t bool last_subreq)\n+void netfs_queue_read(struct netfs_io_request *rreq,\n+\t\t struct netfs_io_subrequest *subreq,\n+\t\t bool last_subreq)\n {\n \tstruct netfs_io_stream *stream = &rreq->io_streams[0];\n \n@@ -169,7 +169,8 @@ static void netfs_queue_read(struct netfs_io_request *rreq,\n \t * remove entries off of the front.\n \t */\n \tspin_lock(&rreq->lock);\n-\tlist_add_tail(&subreq->rreq_link, &stream->subrequests);\n+\t/* Write IN_PROGRESS before pointer to new subreq */\n+\tlist_add_tail_release(&subreq->rreq_link, &stream->subrequests);\n \tif (list_is_first(&subreq->rreq_link, &stream->subrequests)) {\n \t\tif (!stream->active) {\n \t\t\tstream->collected_to = subreq->start;\ndiff --git a/fs/netfs/direct_read.c b/fs/netfs/direct_read.c\nindex f72e6da88cca..69a1a1e26143 100644\n--- a/fs/netfs/direct_read.c\n+++ b/fs/netfs/direct_read.c\n@@ -47,7 +47,6 @@ static void netfs_prepare_dio_read_iterator(struct netfs_io_subrequest *subreq)\n */\n static int netfs_dispatch_unbuffered_reads(struct netfs_io_request *rreq)\n {\n-\tstruct netfs_io_stream *stream = &rreq->io_streams[0];\n \tunsigned long long start = rreq->start;\n \tssize_t size = rreq->len;\n \tint ret = 0;\n@@ -66,19 +65,7 @@ static int netfs_dispatch_unbuffered_reads(struct netfs_io_request *rreq)\n \t\tsubreq->start\t= start;\n \t\tsubreq->len\t= size;\n \n-\t\t__set_bit(NETFS_SREQ_IN_PROGRESS, &subreq->flags);\n-\n-\t\tspin_lock(&rreq->lock);\n-\t\tlist_add_tail(&subreq->rreq_link, &stream->subrequests);\n-\t\tif (list_is_first(&subreq->rreq_link, &stream->subrequests)) {\n-\t\t\tif (!stream->active) {\n-\t\t\t\tstream->collected_to = subreq->start;\n-\t\t\t\t/* Store list pointers before active flag */\n-\t\t\t\tsmp_store_release(&stream->active, true);\n-\t\t\t}\n-\t\t}\n-\t\ttrace_netfs_sreq(subreq, netfs_sreq_trace_added);\n-\t\tspin_unlock(&rreq->lock);\n+\t\tnetfs_queue_read(rreq, subreq, false);\n \n \t\tnetfs_stat(&netfs_n_rh_download);\n \t\tif (rreq->netfs_ops->prepare_read) {\ndiff --git a/fs/netfs/internal.h b/fs/netfs/internal.h\nindex d436e20d3418..964479335ff7 100644\n--- a/fs/netfs/internal.h\n+++ b/fs/netfs/internal.h\n@@ -23,6 +23,9 @@\n /*\n * buffered_read.c\n */\n+void netfs_queue_read(struct netfs_io_request *rreq,\n+\t\t struct netfs_io_subrequest *subreq,\n+\t\t bool last_subreq);\n void netfs_cache_read_terminated(void *priv, ssize_t transferred_or_error);\n int netfs_prefetch_for_write(struct file *file, struct folio *folio,\n \t\t\t size_t offset, size_t len);\ndiff --git a/fs/netfs/read_collect.c b/fs/netfs/read_collect.c\nindex eae067e3eaa5..5847796b54ec 100644\n--- a/fs/netfs/read_collect.c\n+++ b/fs/netfs/read_collect.c\n@@ -205,8 +205,10 @@ static void netfs_collect_read_results(struct netfs_io_request *rreq)\n \t * in progress. The issuer thread may be adding stuff to the tail\n \t * whilst we're doing this.\n \t */\n-\tfront = list_first_entry_or_null(&stream->subrequests,\n+\tfront = list_first_entry_acquire(&stream->subrequests,\n \t\t\t\t\t struct netfs_io_subrequest, rreq_link);\n+\t/* Read first subreq pointer before IN_PROGRESS flag. */\n+\n \twhile (front) {\n \t\tsize_t transferred;\n \ndiff --git a/fs/netfs/read_single.c b/fs/netfs/read_single.c\nindex d0e23bc42445..30e184caadb2 100644\n--- a/fs/netfs/read_single.c\n+++ b/fs/netfs/read_single.c\n@@ -89,7 +89,6 @@ static void netfs_single_read_cache(struct netfs_io_request *rreq,\n */\n static int netfs_single_dispatch_read(struct netfs_io_request *rreq)\n {\n-\tstruct netfs_io_stream *stream = &rreq->io_streams[0];\n \tstruct netfs_io_subrequest *subreq;\n \tint ret = 0;\n \n@@ -102,14 +101,7 @@ static int netfs_single_dispatch_read(struct netfs_io_request *rreq)\n \tsubreq->len\t= rreq->len;\n \tsubreq->io_iter\t= rreq->buffer.iter;\n \n-\t__set_bit(NETFS_SREQ_IN_PROGRESS, &subreq->flags);\n-\n-\tspin_lock(&rreq->lock);\n-\tlist_add_tail(&subreq->rreq_link, &stream->subrequests);\n-\ttrace_netfs_sreq(subreq, netfs_sreq_trace_added);\n-\t/* Store list pointers before active flag */\n-\tsmp_store_release(&stream->active, true);\n-\tspin_unlock(&rreq->lock);\n+\tnetfs_queue_read(rreq, subreq, true);\n \n \tnetfs_single_cache_prepare_read(rreq, subreq);\n \tswitch (subreq->source) {\n@@ -137,8 +129,6 @@ static int netfs_single_dispatch_read(struct netfs_io_request *rreq)\n \t\tbreak;\n \t}\n \n-\tsmp_wmb(); /* Write lists before ALL_QUEUED. */\n-\tset_bit(NETFS_RREQ_ALL_QUEUED, &rreq->flags);\n \treturn ret;\n cancel:\n \tnetfs_put_subrequest(subreq, netfs_sreq_trace_put_cancel);\ndiff --git a/fs/netfs/write_collect.c b/fs/netfs/write_collect.c\nindex 4718e5174d65..f0cafa1d5835 100644\n--- a/fs/netfs/write_collect.c\n+++ b/fs/netfs/write_collect.c\n@@ -227,8 +227,10 @@ static void netfs_collect_write_results(struct netfs_io_request *wreq)\n \t\tif (!smp_load_acquire(&stream->active))\n \t\t\tcontinue;\n \n-\t\tfront = list_first_entry_or_null(&stream->subrequests,\n+\t\tfront = list_first_entry_acquire(&stream->subrequests,\n \t\t\t\t\t\t struct netfs_io_subrequest, rreq_link);\n+\t\t/* Read first subreq pointer before IN_PROGRESS flag. */\n+\n \t\twhile (front) {\n \t\t\ttrace_netfs_collect_sreq(wreq, front);\n \t\t\t//_debug(\"sreq [%x] %llx %zx/%zx\",\ndiff --git a/fs/netfs/write_issue.c b/fs/netfs/write_issue.c\nindex 2db688f94125..b0e9690bb90c 100644\n--- a/fs/netfs/write_issue.c\n+++ b/fs/netfs/write_issue.c\n@@ -204,7 +204,8 @@ void netfs_prepare_write(struct netfs_io_request *wreq,\n \t * remove entries off of the front.\n \t */\n \tspin_lock(&wreq->lock);\n-\tlist_add_tail(&subreq->rreq_link, &stream->subrequests);\n+\t/* Write IN_PROGRESS before pointer to new subreq */\n+\tlist_add_tail_release(&subreq->rreq_link, &stream->subrequests);\n \tif (list_is_first(&subreq->rreq_link, &stream->subrequests)) {\n \t\tif (!stream->active) {\n \t\t\tstream->collected_to = subreq->start;\ndiff --git a/include/linux/list.h b/include/linux/list.h\nindex 00ea8e5fb88b..5af356efd725 100644\n--- a/include/linux/list.h\n+++ b/include/linux/list.h\n@@ -191,6 +191,29 @@ static inline void list_add_tail(struct list_head *new, struct list_head *head)\n \t__list_add(new, head->prev, head);\n }\n \n+/**\n+ * list_add_tail_release - add a new entry with release barrier\n+ * @new: new entry to be added\n+ * @head: list head to add it before\n+ *\n+ * Insert a new entry before the specified head, using a release barrier to set\n+ * the ->next pointer that points to it. This is useful for implementing\n+ * queues, in particular one that the elements will be walked through forwards\n+ * locklessly.\n+ */\n+static inline void list_add_tail_release(struct list_head *new,\n+\t\t\t\t\t struct list_head *head)\n+{\n+\tstruct list_head *prev = head->prev;\n+\n+\tif (__list_add_valid(new, prev, head)) {\n+\t\tnew->next = head;\n+\t\tnew->prev = prev;\n+\t\thead->prev = new;\n+\t\tsmp_store_release(&prev->next, new);\n+\t}\n+}\n+\n /*\n * Delete a list entry by making the prev/next entries\n * point to each other.\n@@ -644,6 +667,20 @@ static inline void list_splice_tail_init(struct list_head *list,\n \tpos__ != head__ ? list_entry(pos__, type, member) : NULL; \\\n })\n \n+/**\n+ * list_first_entry_acquire - get the first element from a list with barrier\n+ * @ptr:\tthe list head to take the element from.\n+ * @type:\tthe type of the struct this is embedded in.\n+ * @member:\tthe name of the list_head within the struct.\n+ *\n+ * Note that if the list is empty, it returns NULL.\n+ */\n+#define list_first_entry_acquire(ptr, type, member) ({ \\\n+\tstruct list_head *head__ = (ptr); \\\n+\tstruct list_head *pos__ = smp_load_acquire(&head__->next); \\\n+\tpos__ != head__ ? list_entry(pos__, type, member) : NULL; \\\n+})\n+\n /**\n * list_last_entry_or_null - get the last element from a list\n * @ptr:\tthe list head to take the element from.\n", "prefixes": [ "v3", "17/19" ] }