Patch Detail
get:
Show a patch.
patch:
Update a patch.
put:
Update a patch.
GET /api/1.1/patches/2227563/?format=api
{ "id": 2227563, "url": "http://patchwork.ozlabs.org/api/1.1/patches/2227563/?format=api", "web_url": "http://patchwork.ozlabs.org/project/linux-cifs-client/patch/20260423222209.3054909-3-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": "<20260423222209.3054909-3-dhowells@redhat.com>", "date": "2026-04-23T22:22:05", "name": "[2/4] 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/20260423222209.3054909-3-dhowells@redhat.com/mbox/", "series": [ { "id": 501258, "url": "http://patchwork.ozlabs.org/api/1.1/series/501258/?format=api", "web_url": "http://patchwork.ozlabs.org/project/linux-cifs-client/list/?series=501258", "date": "2026-04-23T22:22:03", "name": "netfs: Yet further miscellaneous fixes", "version": 1, "mbox": "http://patchwork.ozlabs.org/series/501258/mbox/" } ], "comments": "http://patchwork.ozlabs.org/api/patches/2227563/comments/", "check": "pending", "checks": "http://patchwork.ozlabs.org/api/patches/2227563/checks/", "tags": {}, "headers": { "Return-Path": "\n <linux-cifs+bounces-11070-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=G/ujrSku;\n\tdkim-atps=neutral", "legolas.ozlabs.org;\n spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org\n (client-ip=2600:3c15:e001:75::12fc:5321; helo=sin.lore.kernel.org;\n envelope-from=linux-cifs+bounces-11070-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=\"G/ujrSku\"", "smtp.subspace.kernel.org;\n arc=none smtp.client-ip=170.10.129.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 sin.lore.kernel.org (sin.lore.kernel.org\n [IPv6:2600:3c15:e001:75::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 4g1rFg04g7z1y2d\n\tfor <incoming@patchwork.ozlabs.org>; Fri, 24 Apr 2026 08:23:03 +1000 (AEST)", "from smtp.subspace.kernel.org (conduit.subspace.kernel.org\n [100.90.174.1])\n\tby sin.lore.kernel.org (Postfix) with ESMTP id A01BB3009F3C\n\tfor <incoming@patchwork.ozlabs.org>; Thu, 23 Apr 2026 22:22:41 +0000 (UTC)", "from localhost.localdomain (localhost.localdomain [127.0.0.1])\n\tby smtp.subspace.kernel.org (Postfix) with ESMTP id EC52C37C916;\n\tThu, 23 Apr 2026 22:22:39 +0000 (UTC)", "from us-smtp-delivery-124.mimecast.com\n (us-smtp-delivery-124.mimecast.com [170.10.129.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 207EC3BD651\n\tfor <linux-cifs@vger.kernel.org>; Thu, 23 Apr 2026 22:22:38 +0000 (UTC)", "from mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com\n (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by\n relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3,\n cipher=TLS_AES_256_GCM_SHA384) id us-mta-575-2FfrlDfjOQa16dtGJW9_RA-1; Thu,\n 23 Apr 2026 18:22:32 -0400", "from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com\n (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17])\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-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS\n id 8E2B1195608D;\n\tThu, 23 Apr 2026 22:22:30 +0000 (UTC)", "from warthog.procyon.org.com (unknown [10.44.48.17])\n\tby mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP\n id B0543196B8F6;\n\tThu, 23 Apr 2026 22:22:27 +0000 (UTC)" ], "ARC-Seal": "i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116;\n\tt=1776982959; cv=none;\n b=lRBcueLV/lPQ4S/ksR5kGZvuzpCjMim96Z3DtyUavT17MPl8besHQItTOKLD9gOl7Kh+MnGgOo5VMe4kdmXqgP8m4BUtJjzYQYYTdO0okx6C10EhKZ62dBZz9dtk8hcpdpHH7yXB6qDasXKGVQ4HSHs2oospjnoouVI8DOupbfQ=", "ARC-Message-Signature": "i=1; a=rsa-sha256; d=subspace.kernel.org;\n\ts=arc-20240116; t=1776982959; c=relaxed/simple;\n\tbh=nQcYuDPSsOGJNf916H6peKQku5OR+hGAv0G1GjyDZd0=;\n\th=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References:\n\t MIME-Version;\n b=FmmZcHFK9YNniNXh4GZv+mE4xXwf89wDRPHccEzYUAyHYdI03f9PCR65cRwIsn6HhmpzZccR9KmvkhUkTaVN9PeQo54teBknOv99cPYc3xKcVk0z14+yAsHMjuLvSUAREm1uc/nF+WHVFgI6jGKle1o4oQ4Mx13w2Uo5mE2lDD8=", "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=G/ujrSku; arc=none smtp.client-ip=170.10.129.124", "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com;\n\ts=mimecast20190719; t=1776982957;\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=dSOPAar6dtE7it/Tsf2brwfsDP4VAcVbcSo3XqesRc0=;\n\tb=G/ujrSkufus9Jmq3VREx3T6yrS75vQIYIDGWVDQI67cja+4Cm4sq2HYD+Pg+6cuFwQ9Zkn\n\tyER5EIPv0DFwKwy5RJKBYaDjSBsLYaPfMgmsJ0GH6c5GqetyZCNDORTkqSAMOznlVhicm6\n\t8smbrI3LBl8g84gqsTLAcXPMdWVTyn0=", "X-MC-Unique": "2FfrlDfjOQa16dtGJW9_RA-1", "X-Mimecast-MFC-AGG-ID": "2FfrlDfjOQa16dtGJW9_RA_1776982950", "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 2/4] netfs: Fix missing barriers when accessing\n stream->subrequests locklessly", "Date": "Thu, 23 Apr 2026 23:22:05 +0100", "Message-ID": "<20260423222209.3054909-3-dhowells@redhat.com>", "In-Reply-To": "<20260423222209.3054909-1-dhowells@redhat.com>", "References": "<20260423222209.3054909-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.0 on 10.30.177.17" }, "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 dcfe51eec266..5c78ec14e46b 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": [ "2/4" ] }