From: Usama Arif <[email protected]>
To: [email protected], [email protected], [email protected]
Cc: [email protected], Usama Arif <[email protected]>
Subject: [RFC 1/3] ipc/msg: split do_msgsnd into functions
Date: Mon, 13 Jun 2022 20:26:40 +0100 [thread overview]
Message-ID: <[email protected]> (raw)
In-Reply-To: <[email protected]>
do_msgsnd is split into check_and_load_msgsnd and __do_msgsnd.
This does not introduce any change in the functions' operation.
Its only needed for async msgsnd in io_uring which will be added
in a later patch.
Functions used for msgsnd and msgrcv are also declared in the
header file for use in io_uring patches later.
Signed-off-by: Usama Arif <[email protected]>
---
include/linux/msg.h | 11 ++++++++++
ipc/msg.c | 52 ++++++++++++++++++++++++++++++++++-----------
2 files changed, 51 insertions(+), 12 deletions(-)
diff --git a/include/linux/msg.h b/include/linux/msg.h
index 9a972a296b95..36e3116fed86 100644
--- a/include/linux/msg.h
+++ b/include/linux/msg.h
@@ -15,4 +15,15 @@ struct msg_msg {
/* the actual message follows immediately */
};
+long check_and_load_msgsnd(int msqid, long mtype, void __user *mtext,
+ struct msg_msg **msg, size_t msgsz);
+
+void free_msg(struct msg_msg *msg);
+
+long __do_msgsnd(int msqid, long mtype, struct msg_msg **msg,
+ size_t msgsz, int msgflg);
+
+long ksys_msgrcv(int msqid, struct msgbuf __user *msgp, size_t msgsz,
+ long msgtyp, int msgflg);
+
#endif /* _LINUX_MSG_H */
diff --git a/ipc/msg.c b/ipc/msg.c
index a0d05775af2c..0682204a684e 100644
--- a/ipc/msg.c
+++ b/ipc/msg.c
@@ -839,14 +839,11 @@ static inline int pipelined_send(struct msg_queue *msq, struct msg_msg *msg,
return 0;
}
-static long do_msgsnd(int msqid, long mtype, void __user *mtext,
- size_t msgsz, int msgflg)
+long check_and_load_msgsnd(int msqid, long mtype, void __user *mtext,
+ struct msg_msg **msg, size_t msgsz)
{
- struct msg_queue *msq;
- struct msg_msg *msg;
- int err;
struct ipc_namespace *ns;
- DEFINE_WAKE_Q(wake_q);
+ struct msg_msg *tmp;
ns = current->nsproxy->ipc_ns;
@@ -855,12 +852,45 @@ static long do_msgsnd(int msqid, long mtype, void __user *mtext,
if (mtype < 1)
return -EINVAL;
- msg = load_msg(mtext, msgsz);
+ tmp = load_msg(mtext, msgsz);
if (IS_ERR(msg))
return PTR_ERR(msg);
- msg->m_type = mtype;
- msg->m_ts = msgsz;
+ tmp->m_type = mtype;
+ tmp->m_ts = msgsz;
+
+ *msg = tmp;
+ return 0;
+}
+
+static long do_msgsnd(int msqid, long mtype, void __user *mtext,
+ size_t msgsz, int msgflg)
+{
+ struct msg_msg *msg;
+ int err;
+
+ err = check_and_load_msgsnd(msqid, mtype, mtext, &msg, msgsz);
+ if (err)
+ return err;
+
+ err = __do_msgsnd(msqid, mtype, &msg, msgsz, msgflg);
+ if (msg != NULL)
+ free_msg(msg);
+
+ return err;
+}
+
+long __do_msgsnd(int msqid, long mtype, struct msg_msg **_msg,
+ size_t msgsz, int msgflg)
+{
+ struct msg_queue *msq;
+ struct msg_msg *msg;
+ int err;
+ struct ipc_namespace *ns;
+ DEFINE_WAKE_Q(wake_q);
+
+ msg = *_msg;
+ ns = current->nsproxy->ipc_ns;
rcu_read_lock();
msq = msq_obtain_object_check(ns, msqid);
@@ -940,15 +970,13 @@ static long do_msgsnd(int msqid, long mtype, void __user *mtext,
}
err = 0;
- msg = NULL;
+ *_msg = NULL;
out_unlock0:
ipc_unlock_object(&msq->q_perm);
wake_up_q(&wake_q);
out_unlock1:
rcu_read_unlock();
- if (msg != NULL)
- free_msg(msg);
return err;
}
--
2.25.1
next prev parent reply other threads:[~2022-06-13 20:37 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-06-13 19:26 [RFC 0/3] io_uring: add support for IORING_OP_MSGSND/IORING_OP_MSGRCV Usama Arif
2022-06-13 19:26 ` Usama Arif [this message]
2022-06-13 19:26 ` [RFC 2/3] io_uring: add support for IORING_OP_MSGSND Usama Arif
2022-06-13 19:26 ` [RFC 3/3] io_uring: add support for IORING_OP_MSGRCV Usama Arif
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 \
[email protected] \
[email protected] \
[email protected] \
[email protected] \
[email protected] \
[email protected] \
/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