From: Jason Xing <kerneljasonxing@gmail.com>
To: nbd@nbd.name, lorenzo@kernel.org, ryder.lee@mediatek.com,
shayne.chen@mediatek.com, sean.wang@mediatek.com,
matthias.bgg@gmail.com, angelogioacchino.delregno@collabora.com,
akpm@linux-foundation.org, axboe@kernel.dk
Cc: linux-wireless@vger.kernel.org, Jason Xing <kernelxing@tencent.com>
Subject: [PATCH 1/3] relayfs: introduce relay_subbuf_avail()
Date: Sun, 31 May 2026 11:40:08 +0800 [thread overview]
Message-ID: <20260531034010.85002-2-kerneljasonxing@gmail.com> (raw)
In-Reply-To: <20260531034010.85002-1-kerneljasonxing@gmail.com>
From: Jason Xing <kernelxing@tencent.com>
Add relay_subbuf_avail() which ensures the sub-buffer has room and
returns the buffer pointer without advancing the offset.
Together with __relay_write(), it lets callers emit multi-part records
where the offset only moves after each chunk is copied, closing the
stale-read window.
Signed-off-by: Jason Xing <kernelxing@tencent.com>
---
include/linux/relay.h | 24 ++++++++++++++++++++++++
1 file changed, 24 insertions(+)
diff --git a/include/linux/relay.h b/include/linux/relay.h
index 6772a7075840..270a028586bd 100644
--- a/include/linux/relay.h
+++ b/include/linux/relay.h
@@ -268,6 +268,30 @@ static inline void *relay_reserve(struct rchan *chan, size_t length)
return reserved;
}
+/**
+ * relay_subbuf_avail - ensure @length bytes fit in current sub-buffer
+ * @chan: relay channel
+ * @length: total number of bytes to check
+ *
+ * Returns the per-cpu buffer if @length bytes fit, NULL otherwise.
+ * Switches to the next sub-buffer if necessary but does NOT advance
+ * the write offset. Use __relay_write() to write into the returned
+ * buffer.
+ *
+ * Caller must prevent preemption and serialise against other writers.
+ */
+static inline struct rchan_buf *
+relay_subbuf_avail(struct rchan *chan, size_t length)
+{
+ struct rchan_buf *buf = *this_cpu_ptr(chan->buf);
+
+ if (unlikely(buf->offset + length > buf->chan->subbuf_size)) {
+ if (!relay_switch_subbuf(buf, length))
+ return NULL;
+ }
+ return buf;
+}
+
/**
* subbuf_start_reserve - reserve bytes at the start of a sub-buffer
* @buf: relay channel buffer
--
2.43.7
next prev parent reply other threads:[~2026-05-31 3:40 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-31 3:40 [PATCH 0/3] wifi: mt76: use __relay_write to avoid race issues Jason Xing
2026-05-31 3:40 ` Jason Xing [this message]
2026-05-31 3:40 ` [PATCH 2/3] wifi: mt76: mt7915: use relay_subbuf_avail() to fix stale fwlog reads Jason Xing
2026-05-31 3:40 ` [PATCH 3/3] wifi: mt76: mt7996: " Jason Xing
2026-05-31 5:58 ` [PATCH 0/3] wifi: mt76: use __relay_write to avoid race issues Jason Xing
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260531034010.85002-2-kerneljasonxing@gmail.com \
--to=kerneljasonxing@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=angelogioacchino.delregno@collabora.com \
--cc=axboe@kernel.dk \
--cc=kernelxing@tencent.com \
--cc=linux-wireless@vger.kernel.org \
--cc=lorenzo@kernel.org \
--cc=matthias.bgg@gmail.com \
--cc=nbd@nbd.name \
--cc=ryder.lee@mediatek.com \
--cc=sean.wang@mediatek.com \
--cc=shayne.chen@mediatek.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox