[RFC PATCH 2/3] msg: move struct msg_msgseg and DATALEN_* to include/linux/msg.h

Shaurya Rane posted 3 patches 1 week, 1 day ago
[RFC PATCH 2/3] msg: move struct msg_msgseg and DATALEN_* to include/linux/msg.h
Posted by Shaurya Rane 1 week, 1 day ago
struct msg_msgseg and the DATALEN_MSG / DATALEN_SEG macros are
currently private to ipc/msgutil.c.  struct msg_msg (already in the
public kernel header include/linux/msg.h) carries a pointer to
msg_msgseg, making it an incomplete type for all callers outside
msgutil.c.

Move the definition of struct msg_msgseg and the two DATALEN macros to
include/linux/msg.h so that other IPC code can safely copy
multi-segment message payloads into a kernel buffer under a spinlock,
without calling store_msg() which performs copy_to_user() and therefore
cannot be used under a spinlock.

ipc/msgutil.c already includes <linux/msg.h>, so it picks up the
definitions from the header with no functional change.

Signed-off-by: Shaurya Rane <ssrane_b23@ee.vjti.ac.in>
---
 include/linux/msg.h | 13 +++++++++++++
 ipc/msgutil.c       |  7 -------
 2 files changed, 13 insertions(+), 7 deletions(-)

diff --git a/include/linux/msg.h b/include/linux/msg.h
index 9a972a296b95..2d5353bace9a 100644
--- a/include/linux/msg.h
+++ b/include/linux/msg.h
@@ -5,6 +5,19 @@
 #include <linux/list.h>
 #include <uapi/linux/msg.h>
 
+/*
+ * Each message is stored in one or more page-sized segments.
+ * The first segment is embedded in struct msg_msg; overflow goes into
+ * chained struct msg_msgseg blocks.
+ */
+struct msg_msgseg {
+	struct msg_msgseg *next;
+	/* message data follows immediately */
+};
+
+#define DATALEN_MSG	((size_t)PAGE_SIZE - sizeof(struct msg_msg))
+#define DATALEN_SEG	((size_t)PAGE_SIZE - sizeof(struct msg_msgseg))
+
 /* one msg_msg structure for each message */
 struct msg_msg {
 	struct list_head m_list;
diff --git a/ipc/msgutil.c b/ipc/msgutil.c
index e28f0cecb2ec..9cd4b078d55c 100644
--- a/ipc/msgutil.c
+++ b/ipc/msgutil.c
@@ -31,13 +31,6 @@ struct ipc_namespace init_ipc_ns = {
 	.user_ns = &init_user_ns,
 };
 
-struct msg_msgseg {
-	struct msg_msgseg *next;
-	/* the next part of the message follows immediately */
-};
-
-#define DATALEN_MSG	((size_t)PAGE_SIZE-sizeof(struct msg_msg))
-#define DATALEN_SEG	((size_t)PAGE_SIZE-sizeof(struct msg_msgseg))
 
 static kmem_buckets *msg_buckets __ro_after_init;
 
-- 
2.34.1